The game state can be represented in a lot of different ways, but you will learn how to create extendible classes in order to use the high-level board AI algorithms for different circumstances.
It is important to be clear on object-oriented programming, specifically on inheritance and polymorphism. This is because we'll be creating generic functions that can be applied to a number of board game decisions and then writing specific subclasses that inherit and further specify these functions.
We will build two classes in order to represent game-tree with the help of the following steps:
Move
:using UnityEngine; using System.Collections; public abstract class Move { }
Board
:using UnityEngine; using System.Collections; public class Board { protected int player; //next steps here }
public Board() { player = 1; }
public virtual Move[] GetMoves() { return new Move[0]; }
public virtual Board MakeMove(Move m) { return new Board(); }
public virtual bool IsGameOver() { return true; }
public virtual int GetCurrentPlayer() { return player; }
public virtual float Evaluate(int player) { return Mathf.NegativeInfinity; }
public virtual float Evaluate() { return Mathf.NegativeInfinity; }
We have created the stepping stones for the next algorithms. The Board
class works as a node in order to represent the current game state, and the Move
class represents an edge. When the GetMoves
function is called, we model the function for getting the edges in order to reach the neighbors of the current game state.