コード例 #1
0
        public void Proverka4()  //Stop() Proverka
        {
            // исходные данные
            int  a = 2;
            bool t = true;

            // получение значения с помощью тестируемого метода
            XO x = new XO();

            for (int i = 0; i < 9; i++)
            {
                if (i >= 6)
                {
                    x.GamePoleC[i] = 2;
                }
                else
                if (i <= 1)
                {
                    x.GamePoleC[i] = 1;
                }
                else
                {
                    x.GamePoleC[i] = 0;
                }
            }
            bool r = x.Proverka(2);            // сравнение ожидаемого результата с полученным

            Assert.AreEqual(t, r);
        }
コード例 #2
0
        public void Stop2()  //Stop() Proverka
        {
            // исходные данные
            bool t = false;

            // получение значения с помощью тестируемого метода
            XO x = new XO();

            for (int i = 0; i < 9; i++)
            {
                x.GamePoleC[i] = 1;
            }
            bool r = x.Stop();         // сравнение ожидаемого результата с полученным

            Assert.AreEqual(t, r);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Dimych26/Tic-Toc
        static void Main(string[] args)
        {
            XO xo = new XO();

            do
            {
                xo.DrawInstructions();
                xo.DrawField();
                xo.ChooseOfPlayer();
                xo.numbers++;
                xo.GameOverAll();
                xo.ChooseOfAI();
                xo.numbers++;
                xo.GameOverAll();
                Console.Clear();
            }while (xo.GameOver == false);
        }
コード例 #4
0
        private void GameBoard_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // A Player clicked lets get the column we are on.
            // Lets scan where the mouse is.

            // Get Mouse position relative to GameBoard.
            var point = Mouse.GetPosition(GameBoard);

            var column   = 0;
            var widthSum = 0.0;

            foreach (var columnDefinition in GameBoard.ColumnDefinitions)
            {
                widthSum += columnDefinition.ActualWidth;
                if (widthSum >= point.X)
                {
                    break;
                }
                column++;
            }

            var row = 0;

            // Lets find an empty row.
            for (var i = GameBoard.RowDefinitions.Count - 1; i >= 0; i--)
            {
                var el = GameBoard.Children.Cast <UIElement>().FirstOrDefault(element => Grid.GetColumn(element) == column && Grid.GetRow(element) == i);
                if (el == null)
                {
                    // Its empty. Break loop and assign row number.
                    row = i;
                    break;
                }

                if (i == 0) // We are on the top and there are no empty cells left. Warn the Player.
                {
                    MessageBox.Show("Chosen column is full. Please chose another column");
                    return;
                }
            }

            //Changing players by checking playerTurn
            char XO;

            if (playerTurn % 2 == 0)
            {
                XO = 'X';
            }
            else
            {
                XO = 'O';
            }

            //Adding tile to board every mouse left click
            AddTile(row, column, XO);

            //If we have winner message box pops (player {X or O} WIN !!!) and exit
            int checkWin; //store the CheckFourLine func return value

            checkWin = CheckFourLine(markBoard);
            if (checkWin == 1)
            {
                MessageBox.Show("Player " + XO.ToString() + " WIN !!!");
                Environment.Exit(1);
            }

            playerTurn++;
        }
コード例 #5
0
ファイル: TikTakToe.cs プロジェクト: Mus1cBreaker/TikTakToe
        public MiniMaxNode MiniMax(string newboard, XO player, XO hard, double alpha = double.NegativeInfinity, double beta = double.PositiveInfinity)
        {
            List <string> not_occupied_cells = Get_Not_Occupied_Coordinates(newboard);
            string        state = Get_Game_State(newboard);

            if (state.Contains(hard.ToString()))
            {
                return(new MiniMaxNode {
                    Score = 10
                });
            }
            else if (hard == XO.X && state.Contains('O') || hard == XO.O && state.Contains('X'))
            {
                return(new MiniMaxNode {
                    Score = -10
                });
            }
            else if (state == "Draw")
            {
                return(new MiniMaxNode {
                    Score = 0
                });
            }
            //List<MiniMaxNode> moves = new List<MiniMaxNode>();
            //foreach(string coordinate in not_occupied_cells)
            //{
            //    moves.Add(new MiniMaxNode
            //    {
            //        Index = coordinates[coordinate],
            //        Score = MiniMax(Make_Turn(newboard, coordinate), (XO)((int)player * -1), hard).Score
            //    }
            //    );
            //}
            MiniMaxNode best_move = null;

            if (player == hard)
            {
                double best_score = double.NegativeInfinity;
                foreach (string coordinate in not_occupied_cells)
                {
                    double value = MiniMax(Make_Turn(newboard, coordinate), (XO)((int)player * -1), hard, alpha, beta).Score;
                    if (value > best_score)
                    {
                        best_score = value;
                        best_move  = new MiniMaxNode {
                            Index = coordinates[coordinate], Score = best_score
                        };
                        alpha = Math.Max(alpha, best_score);
                    }
                    if (beta <= alpha)
                    {
                        break;
                    }
                }
                return(best_move);
            }
            else
            {
                double best_score = double.PositiveInfinity;
                foreach (string coodrinate in not_occupied_cells)
                {
                    double value = MiniMax(Make_Turn(newboard, coodrinate), (XO)((int)player * -1), hard, alpha, beta).Score;
                    if (value < best_score)
                    {
                        best_score = value;
                        best_move  = new MiniMaxNode {
                            Index = coordinates[coodrinate], Score = best_score
                        };
                        beta = Math.Max(alpha, best_score);
                    }
                    if (beta <= alpha)
                    {
                        break;
                    }
                }
                return(best_move);
            }
        }
コード例 #6
0
 public CellData(XO _value)
 {
     // Init
     cellValue = _value;
 }
コード例 #7
0
ファイル: Team.cs プロジェクト: LexA4V/TicTacToe
 protected Team(XO name)
 {
     _name = name;
 }