示例#1
0
        public static Move GetMove(string notation)
        {
            Move move;

            if (NotationParser.TryParseNotation(notation, out move))
            {
                move._notation = notation;
                return(move);
            }
            else
            {
                throw new Exception("Bad move notation");
            }
        }
示例#2
0
文件: Board.cs 项目: vfridell/Gipf
        /// <summary>
        /// We create a board by getting a hex of hexes with radius of 4
        /// See http://www.redblobgames.com/grids/hexagons/#range
        /// </summary>
        public static Board GetInitialBoard(GameType gameType = GameType.Tournament)
        {
            Board board = new Board {
                _gameType = gameType
            };

            for (int row = -BoardRadius; row <= BoardRadius; row++)
            {
                int minCol = Math.Max(-BoardRadius, -row - BoardRadius);
                int maxCol = Math.Min(BoardRadius, -row + BoardRadius);

                for (int col = minCol; col <= maxCol; col++)
                {
                    Hex  hex = new Hex(col, row);
                    Cell cell;
                    if (Hex.Distance(Start, hex) >= BoardRadius)
                    {
                        cell = new Wall(board, hex);
                    }
                    else
                    {
                        cell = new Cell(board, hex);
                    }
                    board._cellMap[hex] = cell;
                }
            }
            board.InitCells();
            if (gameType == GameType.Standard)
            {
                board._cellMap[NotationParser.GetHex("e8")].SetPiece(Pieces.BlackGipf);
                board._cellMap[NotationParser.GetHex("b2")].SetPiece(Pieces.BlackGipf);
                board._cellMap[NotationParser.GetHex("h2")].SetPiece(Pieces.BlackGipf);
                board._cellMap[NotationParser.GetHex("e2")].SetPiece(Pieces.WhiteGipf);
                board._cellMap[NotationParser.GetHex("b5")].SetPiece(Pieces.WhiteGipf);
                board._cellMap[NotationParser.GetHex("h5")].SetPiece(Pieces.WhiteGipf);
                board._canPlayGipf[(int)PieceColor.White] = false;
                board._canPlayGipf[(int)PieceColor.Black] = false;
            }
            return(board);
        }
示例#3
0
        public IEnumerator <Cell> GetEnumerator()
        {
            bool seenAllWalls = false;
            bool firstCell    = true;

            while (!seenAllWalls)
            {
                if (firstCell)
                {
                    firstCell = false;
                    yield return(_currentCell);
                }
                else
                {
                    if (!_currentCell.TryGetNeighbor(_currentDirection, out _currentCell))
                    {
                        throw new Exception($"No neighbor in direction {_currentDirection.ToString()}");
                    }

                    Position newDirection;
                    if (_corners.TryGetValue(_currentCell.hex, out newDirection))
                    {
                        _currentDirection = newDirection;
                    }

                    if (_currentCell.hex == NotationParser.GetHex("a1"))
                    {
                        seenAllWalls = true;
                    }
                    else
                    {
                        yield return(_currentCell);
                    }
                }
            }
        }
示例#4
0
 public BoardWallsEnumerable(Board board)
 {
     _board            = board;
     _currentDirection = _corners[NotationParser.GetHex("a1")];
     _currentCell      = board.Cells[NotationParser.GetHex("a1")];
 }