Example #1
0
        public int AddValue(int x, int y, bool showMessage = true)
        {
            if (x > BoardValues.GetLength(0) || y > BoardValues.GetLength(1))
            {
                return(0);
            }
            if (BoardValues[x, y].IsGrain())
            {
                if (showMessage)
                {
                    MessageBox.Show("This pixel is already grained", "Error", MessageBoxButtons.OK);
                }
                return(0);
            }

            var randomColor = InitialValuesGenerator.RandomColor();

            BoardValues[x, y].GrainValue = true;
            BoardValues[x, y].Color      = randomColor;
            Grained.Add(new GamePixelWithCoordinates
            {
                Color      = randomColor,
                GrainValue = true,
                Id         = BoardValues[x, y].Id,
                X          = x,
                Y          = y
            });

            return(1);
        }
Example #2
0
        public BoardMatrix(BoardValues InitValue)
        {
            matrix = new BoardValues[8, 8];

            for (var col = 0; col < 8; col++)
            {
                for (var row = 0; row < 8; row++)
                {
                    matrix[col, row] = InitValue;
                }
            }
        }
Example #3
0
 protected Partition(Position position, ConsoleColor color, BoardValues boardValue)
 {
     this.Position   = position;
     this.Color      = color;
     this.BoardValue = boardValue;
 }
Example #4
0
        // Find the best board value for player1.
        private void BoardValue(out BoardValues bestValue, out int bestR, out int bestC, char player1, char player2, int depth, int maxDepth)
        {
            bestValue = BoardValues.Unknown;
            bestR     = -1;
            bestC     = -1;

            // If we are too deep, then we don't know.
            if ((depth > maxDepth) || (NumSquaresTaken == 9))
            {
                return;
            }

            // Track the worst move for player2.
            BoardValues player2Value = BoardValues.Win;

            // Make test moves.
            for (int row = 0; row < 3; row++)
            {
                for (int col = 0; col < 3; col++)
                {
                    // See if this move is taken.
                    if (Board[row, col] == ' ')
                    {
#if COUNT_MOVES
                        NumMovesTested++;
#endif

                        // Try this move.
                        Board[row, col] = player1;
                        NumSquaresTaken++;

                        // See if this gives player1 a win.
                        if (IsWinner(row, col))
                        {
                            // This gives player1 a win and therefore player2 a loss.
                            // Take this move.
                            bestR        = row;
                            bestC        = col;
                            player2Value = BoardValues.Loss;
                        }
                        else
                        {
                            // Recursively try moves for player2.
                            int         testR     = -1;
                            int         testC     = -1;
                            BoardValues testValue = BoardValues.None;
                            BoardValue(out testValue, out testR, out testC,
                                       player2, player1, depth + 1, maxDepth);

                            // See if this is an improvement for player 2.
                            if (player2Value >= testValue)
                            {
                                bestR        = row;
                                bestC        = col;
                                player2Value = testValue;
                            }
                        }

                        // Undo the move.
                        Board[row, col] = ' ';
                        NumSquaresTaken--;
                    }

                    // If player2 will lose, stop searching.
                    if (player2Value == BoardValues.Loss)
                    {
                        break;
                    }
                }
                // If player2 will lose, stop searching.
                if (player2Value == BoardValues.Loss)
                {
                    break;
                }
            } // End making test moves.

            // We now know the worst we can force player2 to do.
            // Convert that into a board value for player1.
            if (player2Value == BoardValues.Loss)
            {
                bestValue = BoardValues.Win;
            }
            else if (player2Value == BoardValues.Win)
            {
                bestValue = BoardValues.Loss;
            }
            else
            {
                bestValue = player2Value;
            }

            // Parameters bestValue, bestR, and bestC contain the best move we found.
        }
Example #5
0
    public List<BoardPoint> GetValidPointList(BoardValues putColor)
    {
        var validPointList = new List<BoardPoint>();

        foreach (BoardPoint point in AllBoardPoint)
        {
            if (boardMatrix.Get(point.col, point.row) == BoardValues.Empty)
            {
                if(IsValidPoint(point.col, point.row, putColor))
                {
                    validPointList.Add(new BoardPoint(point.col, point.row));
                }
            }
        }

        return validPointList;
    }
Example #6
0
 public bool IsValidPoint(int putCol, int putRow, BoardValues putColor)
 {
     if (GetReversePointList(putCol, putRow, putColor).Count > 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #7
0
 public void SetPoint(int col, int row, BoardValues value)
 {
     boardMatrix.Set(col, row, value);
 }
Example #8
0
    /// <summary>
    /// 石を置いた座標から、8方向を探索し、引っくり返しが発生する座標のリストを作成
    /// </summary>
    public List<BoardPoint> GetReversePointList(int putCol, int putRow, BoardValues putColor)
    {
        var reversePointList = new List<BoardPoint>();
        var tmpReversePointList = new List<BoardPoint>();

        var myColor = putColor;
        var targetColor = (myColor == BoardValues.Black) ? BoardValues.White : BoardValues.Black;

        // 探索の共通処理
        System.Func<int, int, bool> searchProcess = (col, row) =>
        {
            var searchPointValue = boardMatrix.Get(col, row);

            // 空
            if (searchPointValue == BoardValues.Empty)
            {
                return true;
            }

            // 置かれた石と同じ色
            if (searchPointValue == myColor)
            {
                reversePointList.AddRange(tmpReversePointList);
                return true;
            }

            // 置かれた石と違う色
            if (searchPointValue == targetColor)
            {
                tmpReversePointList.Add(new BoardPoint(col, row));
            }

            return false;
        };

        // 北方向
        for (var col = putCol - 1; col >= 0; col--)
        {
            if (searchProcess(col, putRow))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 北東方向
        for (int col = putCol - 1, row = putRow + 1; col >= 0 && row <= 7; col--, row++)
        {
            if (searchProcess(col, row))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 東方向
        for (var row = putRow + 1; row <= 7; row++)
        {
            if (searchProcess(putCol, row))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 南東方向
        for (int col = putCol + 1, row = putRow + 1; col <= 7 && row <= 7; col++, row++)
        {
            if (searchProcess(col, row))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 南方向
        for (var col = putCol + 1; col <= 7; col++)
        {
            if (searchProcess(col, putRow))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 南西方向
        for (int col = putCol + 1, row = putRow - 1; col <= 7 && row >= 0; col++, row--)
        {
            if (searchProcess(col, row))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 西方向
        for (var row = putRow - 1; row >= 0; row--)
        {
            if (searchProcess(putCol, row))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        // 北西方向
        for (int col = putCol - 1, row = putRow - 1; col >= 0 && row >= 0; col--, row--)
        {
            if (searchProcess(col, row))
            {
                break;
            }
        }
        tmpReversePointList.Clear();

        return reversePointList;
    }
Example #9
0
 public Result(bool[,] board, BoardValues boardValues)
 {
     Board = board;
     Error = BoardHelper.CheckForErrors(boardValues, board);
 }
Example #10
0
 public void Set(int col, int row, BoardValues value)
 {
     matrix[col, row] = value;
 }