public FormGameProcess(int N, Color a, Color b) : this()
 {
     _NewGameField    = new FieldContext(N);
     _User            = new RealPlayer(a);
     _Bot             = new BotPlayer(b);
     _CellSize.Width  = GetCellSize().Width;
     _CellSize.Height = GetCellSize().Height;
 }
Beispiel #2
0
        public void GetFromConsoleUserStep(FieldContext gameProcess, PlayerCell first)
        {
            string a   = Console.ReadLine();
            int    col = 0;

            for (int i = 0; i < a.Length; i++)
            {
                col *= 10;
                int c = a[i] - '0';
                col += c;
            }
            MakeStep(col, gameProcess, first);
        }
Beispiel #3
0
        public static long heuristic(FieldContext gameProcess, PlayerCell first, PlayerCell flag)
        {
            long score = 0;

            score = HeuristicHero(gameProcess, first, flag);

            if (Math.Abs(score) >= 1e12)
            {
                return(score);
            }

            long oppositeScore = 0;

            oppositeScore = heuristicAntagonist(gameProcess, first, gameProcess.GetOppositePlayer(flag)); //при этой и нижней строке одинаковый результат
                                                                                                          //	oppositeScore = heuristicUser(n, field, first, getOppositeFlag(flag));
            score += oppositeScore;
            return(score);
        }
Beispiel #4
0
        public static Line[] DiagRight(FieldContext gameProcess, PlayerCell flag)
        {
            Line[] ArrDiag = new Line[(gameProcess.QuanCols) * (gameProcess.QuanRows)];
            int    N       = 1;

            bool[,] check = new bool[gameProcess.QuanRows, gameProcess.QuanCols];

            for (int i = 0; i < gameProcess.QuanRows; i++)
            {
                Line a = EmptyLine;
                a.length = 0;
                a.x_coor = i;
                for (int j = 0; j < gameProcess.QuanCols; j++)
                {
                    a.y_coor = j;
                    if (check[i, j] == false && gameProcess.Field[i, j] == flag)
                    {
                        a.length = 0;
                        for (int k = 0; (k + j < gameProcess.QuanCols) && (k + i < gameProcess.QuanRows); k++)
                        {
                            PlayerCell d = gameProcess.Field[k + i, k + j];
                            if (d == flag)
                            {
                                a.length++;
                                check[k + i, k + j] = true;
                            }
                            if ((d != flag || i + k == 2 * gameProcess.N - 2 || j + k == 2 * gameProcess.N - 1) && a.length != 0)
                            {
                                ArrDiag[N++] = a;
                                a.length     = 0;
                                break;
                            }
                        }
                    }
                }
            }
            ArrDiag[0].length = N;
            return(ArrDiag);
        }
Beispiel #5
0
        private static long heuristicAntagonist(FieldContext gameProcess, PlayerCell first, PlayerCell flag)
        {
            long score = 0;

            Line[] arr = LinesCounter.DiagLeft(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            arr    = LinesCounter.DiagRight(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            arr    = LinesCounter.HorLines(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            arr    = LinesCounter.VerLines(gameProcess, flag);
            score += HeuristicLineAntagonist(arr, gameProcess.N, first, flag);

            if (flag == PlayerCell.Antagonist)//bot
            {
                score = (-1) * score;
            }

            return(score);
        }
Beispiel #6
0
 public void MakeStep(int col, FieldContext gameProcess, PlayerCell first)
 {
     gameProcess.FillField(col, PlayerCell.Hero);
 }
Beispiel #7
0
        StepScore Minimax(FieldContext gameProcess, PlayerCell first, PlayerCell flag, int deep, int col, Win aWin)
        {
            StepScore s = StepScoreZero;

            if (deep != 0)
            {
                gameProcess.Field[gameProcess.FreePositions[col], col] = gameProcess.GetOppositePlayer(flag);//(flag % 2) + 1;-opposite
                gameProcess.FreePositions[col]++;
            }
            int c = gameProcess.EndOfTheGame(gameProcess.GetOppositePlayer(flag));

            aWin.W = 0;
            if (c != -1 && deep == 1)
            {
                s.Score = Heuristic.heuristic(gameProcess, first, gameProcess.GetOppositePlayer(flag));
                s.Step  = col;
                aWin.W  = 1;
                gameProcess.FreePositions[col]--;
                gameProcess.Field[gameProcess.FreePositions[col], col] = 0;
                return(s);
            }
            if (c != -1 || deep == 3)
            {
                if (col != -1)
                {
                    s.Score = Heuristic.heuristic(gameProcess, first, gameProcess.GetOppositePlayer(flag));
                    s.Step  = col;
                    gameProcess.FreePositions[col]--;//не работает
                    gameProcess.Field[gameProcess.FreePositions[col], col] = 0;
                    return(s);
                }
            }

            StepScore a = StepScoreZero;

            a.Step = -1;

            if ((deep + 1) % 2 == 0)
            {
                a.Score = (long)-1e15;
            }
            else
            {
                a.Score = (long)1e15;
            }

            for (int i = 0; i < gameProcess.QuanCols; i++)
            {
                if (gameProcess.FreePositions[i] != gameProcess.QuanRows)
                {
                    StepScore f = Minimax(gameProcess, first, gameProcess.GetOppositePlayer(flag), deep + 1, i, aWin);
                    if (aWin.W != 0)
                    {
                        return(f);
                    }
                    if ((deep + 1) % 2 == 0 && a.Score < f.Score)
                    {
                        a.Score = f.Score;
                        a.Step  = i;
                    }

                    if ((deep + 1) % 2 != 0 && a.Score > f.Score)
                    {
                        a.Score = f.Score;
                        a.Step  = i;
                    }
                }
            }
            if (deep != 0)
            {
                gameProcess.FreePositions[col]--;
                gameProcess.Field[gameProcess.FreePositions[col], col] = 0;
            }
            return(a);
        }