FIFA场景逻辑

时间:2013-01-24 00:11:50

标签: algorithm functional-programming logic game-engine game-physics

我总是想知道FIFA的(游戏)逻辑。

他们是否依赖大量if语句来制定游戏规则和其他鲁莽事物?

像:

if( ball.x > areaLeft.x || ball.y > areaTop.y ) {
     out();
}

if( playersCollision > 100 ) {
    giveFoul(firstPlayer, secondPlayer);
}

等等。这些东西真的“如果”还是有其他替代品吗?

2 个答案:

答案 0 :(得分:1)

绝对不是“如果”。那将是一团糟。 Expert systems是为处理这类案件而设立的,您希望维护一个受复杂规则约束的知识库。 我们的想法是,您使用基于逻辑的语言编写一组规则。例如。

giveFoul(Context) :- 
    closePlayers(Context, A, B),
    attackingPlayer(context, A, B),
    defendingSkills(A, ASkill),
    ASkill < 80
    ...

closePlayers(Context, A, B) :-
    position(Context, A, CoordXA, CoordYA),
    position(Context, B, CoordXB, CoordYB),
    ...

您可以看到,使用这种方法,您可以通过重新定义这些规则来改变系统的行为,并让您的推理系统完成其余的工作。

答案 1 :(得分:1)

等式中总是有 ifs 。事情是它比算法建议的简单,主要是因为它不是由计算机决定,而是由一个或多个人决定... [尤其是国际足联,因为他们不想实施基于视频的仲裁]

无论如何,它更像是

 // x in [0,99], the higher x is, the more probable the event is
 function fate(x) {
    return (random () % 100) <= x)
 }

 // if ball out, 75% chance there is an out event
 if( (ball.x > areaLeft.x || ball.y > areaTop.y) && fate(75) ) {
   out();
 }

 // if there is a collision, 50% chance the referee gives a foul 
 if( playersCollision > 100 && fate(50)) {
   giveFoul(firstPlayer,secondPlayer);
 }

etc....