5
$\begingroup$

When Google researchers created AlphaGo, how did they simulate the game of Go? If I wanted to take the same approach to other games, like Risk, how would I go about coding the rules of the game? Is there a programming package, book, or general technique for coding the rules of a game for deep learning?

$\endgroup$
7
$\begingroup$

The rules of a game are traditional coded in the game-engine. That is a module in software, which takes the input of the player (in chess for example “a2a4”) and executes the move. The game-engine can validate if a move is legal and what the new state is, that means on which position every piece is located. Implementing a game-engine depends on the game. A game-engine for “Angry birds” looks different from a game-engine for chess. The first one is a physics based game-engine, while the second one works on a symbolic level. Board games like Go, monopoly and reversi have an easy to implement game-engine, that means it works mostly with a table in which the positions of pieces are stored.

A general rule for implement game-engines for every game is not possible. What game-engines have in common is that they are all computerprograms which can be executed on turing-machines. That means, it is not possible to implement a game-engine without a computer. The reason is, that a command like “If” and “for-loop” are necessary to implement the rules.

The task of creating the rules for a new game can not be done automatically (rule learning for general game playing). It is a manually driven software engineering task which is done inside agile projects, version control and the reuse of existing software. For example, if someone needs a gameengine for pacman, he will look at github for an existing game and study the sourcecode.

In the context of github, the game-engine is called "game rule engine". That is a stripped-down version without 2d graphics and sound which contains only the logical rules. The following example contains a player, which can be moved on a board in 4 directions. It can be triggered by an external class by sending a command to the engine.

class Physics {
public:
  sf::Vector2f pos={100,100};
  std::string action;
  void runaction(std::string name) {
    if (name=="nop") ; // no operation
    if (name=="left") pos={pos.x-10,pos.y};
    if (name=="right") pos={pos.x+10,pos.y};
    if (name=="up") pos={pos.x,pos.y-10}; 
    if (name=="down") pos={pos.x,pos.y+10};
    action=name;
  }
};
$\endgroup$
  • 1
    $\begingroup$ Thanks for the explanation of a game engine! Is there a particular GitHub project with a game engine you would recommend studying (preferably written in Python)? $\endgroup$ – wherestheforce Apr 5 '18 at 17:56
  • $\begingroup$ In chess there is a python-chess package that shows all the allowed moves in chess (board.legal_moves). But chess rules are complicated. $\endgroup$ – keiv.fly Aug 23 '18 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.