示例#1
0
        /// <summary>
        /// +1 for every white
        /// -1 for every black
        /// </summary>
        /// <returns></returns>
        public int GetBoardScore(GameContext context)
        {
            int totalScore      = 0;
            int totalExtraScore = 0;

            bool hasEmptyCell = false;
            int  edgeRows     = context.rows - 1;
            int  edgeColumns  = context.columns - 1;

            for (int r = 0; r < context.rows; r++)
            {
                for (int c = 0; c < context.columns; c++)
                {
                    UInt64 mask = BitBoard.Mask(r, c);
                    if (!BitBoard.GetValue(_hasColorBoard, mask))
                    {
                        hasEmptyCell = true;
                        continue;
                    }
                    int baseScore  = 1;
                    int extraScore = 0;
                    if (r == 0 || r == edgeRows)
                    {
                        extraScore += 5;
                    }
                    if (c == 0 || c == edgeColumns)
                    {
                        extraScore += 5;
                    }
                    if (BitBoard.GetValue(_colorBoard, mask))
                    {
                        totalExtraScore += extraScore;
                        totalScore      += baseScore;
                    }
                    else
                    {
                        totalExtraScore -= extraScore;
                        totalScore      -= baseScore;
                    }
                }
            }

            if (hasEmptyCell)
            {
                return(totalScore + totalExtraScore);
            }
            return(totalScore);
        }
示例#2
0
        public void SetCell(int row, int column, int cellValue)
        {
            UInt64 mask = BitBoard.Mask(row, column);

            if (cellValue == CellEmpty)
            {
                BitBoard.SetValue(ref _hasColorBoard, mask, false);
                BitBoard.SetValue(ref _colorBoard, mask, false);
            }
            else if (cellValue == CellBlack)
            {
                BitBoard.SetValue(ref _hasColorBoard, mask, true);
                BitBoard.SetValue(ref _colorBoard, mask, false);
            }
            else if (cellValue == CellWhite)
            {
                BitBoard.SetValue(ref _hasColorBoard, mask, true);
                BitBoard.SetValue(ref _colorBoard, mask, true);
            }
        }
示例#3
0
        public int GetCell(int row, int column)
        {
            UInt64 mask = BitBoard.Mask(row, column);

            if (BitBoard.GetValue(_hasColorBoard, mask))
            {
                if (BitBoard.GetValue(_colorBoard, mask))
                {
                    return(CellWhite);
                }
                else
                {
                    return(CellBlack);
                }
            }
            else
            {
                return(CellEmpty);
            }
        }
示例#4
0
        public bool TryPlace(GameContext context, int row, int column, int colorCell)
        {
            UInt64 mask = BitBoard.Mask(row, column);

            if (BitBoard.GetValue(_hasColorBoard, mask))
            {
                return(false);
            }

            bool canPlace = false;

            for (int direction = 0; direction < 8; direction++)
            {
                int neighbourRow    = row;
                int neighbourColumn = column;
                if (!GetNeighbour(context, direction, ref neighbourRow, ref neighbourColumn))
                {
                    continue;
                }

                int neighbourCell = GetCell(neighbourRow, neighbourColumn);
                if (neighbourCell == CellEmpty)
                {
                    continue;
                }
                if (neighbourCell == colorCell)
                {
                    continue;                             // friendly units
                }
                int  cursorRow    = neighbourRow;
                int  cursorColumn = neighbourColumn;
                bool success      = false;
                while (true)
                {
                    if (!GetNeighbour(context, direction, ref cursorRow, ref cursorColumn))
                    {
                        break;
                    }

                    UInt64 cursorMask = BitBoard.Mask(cursorRow, cursorColumn);
                    int    cursorCell = GetCell(cursorRow, cursorColumn);
                    if (cursorCell == CellEmpty)
                    {
                        break;
                    }
                    if (cursorCell != colorCell)
                    {
                        continue;
                    }

                    /// found closing
                    success = true;
                    break;
                }

                if (success)
                {
                    canPlace = true;

                    cursorRow    = neighbourRow;
                    cursorColumn = neighbourColumn;
                    SetCell(cursorRow, cursorColumn, colorCell);

                    while (true)
                    {
                        if (!GetNeighbour(context, direction, ref cursorRow, ref cursorColumn))
                        {
                            break;
                        }

                        UInt64 cursorMask = BitBoard.Mask(cursorRow, cursorColumn);
                        int    cursorCell = GetCell(cursorRow, cursorColumn);
                        if (cursorCell == CellEmpty)
                        {
                            break;
                        }
                        if (cursorCell != colorCell)
                        {
                            SetCell(cursorRow, cursorColumn, colorCell);
                            continue;
                        }
                        break;
                    }
                }
            }

            if (canPlace)
            {
                SetCell(row, column, colorCell);
                return(true);
            }
            return(false);
        }