public AICreeperBoard(CreeperBoard board)
        {
            _tileRows = CreeperBoard.TileRows;
            _pegRows = CreeperBoard.PegRows;

            BlackTileCount = 0;
            WhiteTileCount = 0;
            BlackPegs = new HashSet<AIBoardNode>();
            WhitePegs = new HashSet<AIBoardNode>();

            TileHistory = new Stack<CreeperColor>();
            MoveHistory = new Stack<Move>();
            GameStateHistory = new Stack<CreeperGameState>();

            TileBoard = new AIBoardNode[_tileRows, _tileRows];
            PegBoard = new AIBoardNode[_pegRows, _pegRows];
            RowHeadBlack = new AIBoardNode[_tileRows];
            RowHeadWhite = new AIBoardNode[_tileRows];
            ColumnHeadBlack = new AIBoardNode[_tileRows];
            ColumnHeadWhite = new AIBoardNode[_tileRows];

            foreach (Piece tile in board.Tiles)
            {
                TileBoard[tile.Position.Row, tile.Position.Column] = new AIBoardNode(tile.Position.Row, tile.Position.Column, tile.Color);
            }

            foreach (Piece peg in board.Pegs)
            {
                PegBoard[peg.Position.Row, peg.Position.Column] = new AIBoardNode(peg.Position.Row, peg.Position.Column, peg.Color);
                if (peg.Color == CreeperColor.Ice)
                {
                    BlackPegs.Add(PegBoard[peg.Position.Row, peg.Position.Column]);
                }
                else if (peg.Color == CreeperColor.Fire)
                {
                    WhitePegs.Add(PegBoard[peg.Position.Row, peg.Position.Column]);
                }
            }

            for (int row = 0; row < _tileRows; row++)
            {
                for (int column = 0; column < _tileRows; column++)
                {
                    if (TileBoard[row, column].Color == CreeperColor.Ice || TileBoard[row, column].Color == CreeperColor.Fire)
                    {
                        UpdateListHeads(row, column, TileBoard[row, column].Color);
                        AddTileToTeam(TileBoard[row, column]);
                    }
                }
            }

            //Hash = new AIHash(this);
        }
Beispiel #2
0
 public AIBoardNode(AIBoardNode node)
 {
     Color = node.Color;
     Row = node.Row;
     Column = node.Column;
 }
        private void RemoveTileFromTeam(AIBoardNode tile)
        {
            tile.TeamNorth.TeamSouth = tile.TeamSouth;
            tile.TeamSouth.TeamNorth = tile.TeamNorth;
            tile.TeamEast.TeamWest = tile.TeamWest;
            tile.TeamWest.TeamEast = tile.TeamEast;

            if (tile.Color == CreeperColor.Ice)
            {
                if (--BlackTileCount < 0) throw new InvalidOperationException(BlackTileCount.ToString());
            }
            else if (tile.Color == CreeperColor.Fire)
            {
                if (--WhiteTileCount < 0) throw new InvalidOperationException(WhiteTileCount.ToString());
            }
        }
        private void AddTileToTeam(AIBoardNode tile)
        {
            tile.TeamNorth = GetNextNode(tile.Row, tile.Column, CardinalDirection.North);
            tile.TeamSouth = GetNextNode(tile.Row, tile.Column, CardinalDirection.South);
            tile.TeamEast = GetNextNode(tile.Row, tile.Column, CardinalDirection.East);
            tile.TeamWest = GetNextNode(tile.Row, tile.Column, CardinalDirection.West);

            if ((tile.Color == CreeperColor.Ice))
            {
                if (++BlackTileCount > 32) throw new InvalidOperationException(BlackTileCount.ToString() + " is too big!");
            }

            else if (tile.Color == CreeperColor.Fire)
            {
                if (++WhiteTileCount > 32) throw new InvalidOperationException(WhiteTileCount.ToString() + " is too big!");
            }

            if (WhiteTileCount + BlackTileCount > 32)
            {
                throw new InvalidOperationException(WhiteTileCount.ToString() + " is too big!");
            }
        }
 public IEnumerable<AIBoardNode> GetNeighbors(AIBoardNode node, CreeperColor color)
 {
     foreach (Position neighborPosition in new[]{
         new Position(node.Row - 1, node.Column),
         new Position(node.Row + 1, node.Column),
         new Position(node.Row, node.Column - 1),
         new Position(node.Row, node.Column + 1),
     })
     {
         if (IsValidPosition(neighborPosition.Row, neighborPosition.Column, PieceType.Tile)
             && TileBoard[neighborPosition.Row, neighborPosition.Column].Color == color)
         {
             yield return TileBoard[neighborPosition.Row, neighborPosition.Column];
         }
     }
 }