/// <summary> /// Deep copy constructor /// </summary> /// <param name="src"></param> public GameState(GameState src) { Board = new TakBoard(src.Board); White = new PlayerState(src.White); Black = new PlayerState(src.Black); TurnNumber = src.TurnNumber; }
public GameState(TakBoard board) { Board = board; White = new PlayerState(TakPiece.PieceColor.White, Board.Size); Black = new PlayerState(TakPiece.PieceColor.Black, Board.Size); TurnNumber = 0; }
private bool IsLegalPlace(GameState game, out string reason) { TakBoard boardState = game.Board; if (game.TurnNumber == 0 && (Piece == TakPiece.PieceType.Capstone || Piece == TakPiece.PieceType.Wall)) { reason = "Opening move must be a flat"; return(false); } else if (Piece == TakPiece.PieceType.Capstone && game[PieceColor].NumCapstones <= 0) { reason = "Out of capstones"; return(false); } else if (Piece != TakPiece.PieceType.Capstone && game[PieceColor].NumPieces <= 0) { reason = "Out of stones"; return(false); } else if (boardState[Row, Column].Size == 0) { reason = ""; return(true); } else { reason = "Cannot place a piece on a stack"; return(false); } }
/// <summary> /// Is this a legal move for the state of the game? /// </summary> /// <param name="boardState"></param> /// <returns></returns> public bool IsLegal(GameState game, out string reason) { TakBoard boardState = game.Board; if (Row < 0 || Row >= boardState.Size || Column < 0 || Column >= boardState.Size) { reason = "Invalid coordinate"; return(false); } if (Type == MoveType.Place) { return(IsLegalPlace(game, out reason)); } else { return(IsLegalMove(game, out reason)); } }
public BoardGraph(TakBoard board, TakPiece.PieceColor player) { Vertices = new List <Vertex>(); VerticesByCoordinate = new Dictionary <Point, Vertex>(); for (int i = 0; i < board.Size; i++) { for (int j = 0; j < board.Size; j++) { if (board[i, j].Owner == player && !board[i, j].Top.IsWall) { Vertex v = new Vertex() { Row = i, Column = j }; VerticesByCoordinate.Add(new Point(i, j), v); Vertices.Add(v); } } } for (int i = 0; i < Vertices.Count; i++) { Vertex p = Vertices[i]; for (int j = i; j < Vertices.Count; j++) { Vertex q = Vertices[j]; if ((Math.Abs(q.Row - p.Row) == 1 && q.Column == p.Column) || (Math.Abs(q.Column - p.Column) == 1 && q.Row == p.Row)) { q.Adjacencies.Add(p); p.Adjacencies.Add(q); } } } }
private bool IsLegalMove(GameState game, out string reason) { TakBoard boardState = game.Board; // if we're moving more pices than are in the stack if (boardState[Row, Column].Size < NumMoved || boardState[Row, Column].Size == 0) { reason = "Not enough pieces in stack"; return(false); } // we actually own the stack being moved if (boardState[Row, Column].Top.Color != PieceColor) { reason = "Stack belongs to another player"; return(false); } // if we're moving more pieces than the carry limit if (boardState.Size < NumMoved) { reason = "Carry limit exceeded"; return(false); } // if we're moving so far that we'd fall off the edge of the board if ((Direction == MoveDirection.Up && Row + Drops.Count >= boardState.Size) || (Direction == MoveDirection.Down && Row - Drops.Count < 0) || (Direction == MoveDirection.Right && Column + Drops.Count >= boardState.Size) || (Direction == MoveDirection.Left && Column - Drops.Count < 0)) { reason = "Not enough room to move in that direction"; return(false); } // if we're placing non-capstones on walls, or any piece on a capstone int dR, dC; if (Direction == MoveDirection.Left) { dR = 0; dC = -1; } else if (Direction == MoveDirection.Right) { dR = 0; dC = 1; } else if (Direction == MoveDirection.Up) { dR = 1; dC = 0; } else { dR = -1; dC = 0; } PieceStack src = boardState[Row, Column].NonDestructiveGrab(NumMoved); for (int i = 0; i < Drops.Count; i++) { int row = Row + dR * (i + 1); int col = Column + dC * (i + 1); PieceStack dst = boardState[row, col]; if (!src.CanDrop(dst, Drops[i])) { reason = string.Format("Cannot drop piece on {0}{1}", (char)(col + 'a'), row + 1); return(false); } src.Drop(Drops[i]); } // if we reach here then the move is legal reason = ""; return(true); }