private static BoardLocation GetFirstNonEmptyInDirection(Board board, BoardLocation location, int directionX, int directionY) { int x = location.X; int y = location.Y; do { x += directionX; y += directionY; } while (BoardLocation.IsLegal(x, y) && (board.GetOwner(new BoardLocation(x, y)) == Player.None)); if (!BoardLocation.IsLegal(x, y)) { return(null); } BoardLocation newLocation = new BoardLocation(x, y); if (newLocation == location || board.GetOwner(newLocation) == Player.None) { return(null); } else { return(newLocation); } }
private static IEnumerable <BoardLocation> AllLegalBoardLocations() { for (int y = 0; y < 9; y++) { for (int x = 0; x < 9; x++) { if (BoardLocation.IsLegal(x, y)) { yield return(new BoardLocation(x, y)); } } } }
public static void CalculateGameState(Board board, Player me) { myPossibleToLocations.Clear(); myPossibleFromLocations.Clear(); myAttackMoves.Clear(); myLocations.Clear(); myMaxStoneHeight[Stone.boulder] = 0; myMaxStoneHeight[Stone.pebble] = 0; myMaxStoneHeight[Stone.rock] = 0; hisMaxStoneheight[Stone.boulder] = 0; hisMaxStoneheight[Stone.pebble] = 0; hisMaxStoneheight[Stone.rock] = 0; myHighest = 0; hisAttackMoves.Clear(); hisLocations.Clear(); hisPossibleFromLocations.Clear(); hisPossibleToLocations.Clear(); for (int y = 0; y < 9; y++) { for (int x = 0; x < 9; x++) { if (BoardLocation.IsLegal(x, y)) { var location = new BoardLocation(x, y); Stone stone = board.GetStone(location); if (stone != Stone.None) { int height = board.GetHeight(location); if (board.GetOwner(location) == me) { myLocations.Add(location); myPossibleToLocations.Add(location, new List <BoardLocation>()); myPossibleFromLocations.Add(location, new List <BoardLocation>()); myAttackMoves.Add(location, new List <BoardLocation>()); if (height > myMaxStoneHeight[stone]) { myMaxStoneHeight[stone] = height; } if (height > myHighest) { myHighest = height; } } else { hisLocations.Add(location); hisPossibleToLocations.Add(location, new List <BoardLocation>()); hisPossibleFromLocations.Add(location, new List <BoardLocation>()); hisAttackMoves.Add(location, new List <BoardLocation>()); if (height > hisMaxStoneheight[stone]) { hisMaxStoneheight[stone] = height; } } GetPossibleToLocations(board, location, me); GetPossibleFromLocations(board, location, me); } } } } }