예제 #1
0
        public BoardId GetState()
        {
            BoardId id    = new BoardId();
            int     count = 0;

            for (var i = 0; i < Size; i++)
            {
                for (var j = 0; j < Size; j++)
                {
                    if (_squares[i, j].Value != null)
                    {
                        ulong shifted = ValueToShift << count;

                        if (_squares[i, j].Value.Color == PieceColor.Black)
                        {
                            if (!_squares[i, j].Value.IsChecker)
                            {
                                id.Black |= shifted;
                            }
                            else
                            {
                                id.BlackCheckers |= shifted;
                            }
                        }
                        else if (_squares[i, j].Value.Color == PieceColor.White)
                        {
                            if (!_squares[i, j].Value.IsChecker)
                            {
                                id.White |= shifted;
                            }
                            else
                            {
                                id.WhiteCheckers |= shifted;
                            }
                        }
                    }

                    count++;
                }
            }

            return(id);
        }
예제 #2
0
        public void SetState(BoardId id)
        {
            ClearBoard();
            int count = 0;

            for (var i = 0; i < Size; i++)
            {
                for (var j = 0; j < Size; j++)
                {
                    ulong shifted = ValueToShift << count;

                    if ((id.White & shifted) != 0)
                    {
                        _squares[i, j].SetValue(PieceColor.White);
                    }
                    else if ((id.WhiteCheckers & shifted) != 0)
                    {
                        _squares[i, j].SetValue(new Piece(PieceColor.White)
                        {
                            IsChecker = true
                        });
                    }
                    else if ((id.Black & shifted) != 0)
                    {
                        _squares[i, j].SetValue(PieceColor.Black);
                    }
                    else if ((id.BlackCheckers & shifted) != 0)
                    {
                        _squares[i, j].SetValue(new Piece(PieceColor.Black)
                        {
                            IsChecker = true
                        });
                    }

                    count++;
                }
            }
        }