Ejemplo n.º 1
0
        public static Tuple <Connect6Move, double> GetBestMove(Connect6State state)
        {
            if (state.IsFinal())
            {
                if (state.IsSix(state.currentPlayer))
                {
                    return(new Tuple <Connect6Move, double>(null, double.PositiveInfinity));
                }
                if (state.IsTied())
                {
                    return(new Tuple <Connect6Move, double>(null, 0));
                }
                else
                {
                    return(new Tuple <Connect6Move, double>(null, double.NegativeInfinity));
                }
            }

            double       bestscore = double.NegativeInfinity;
            Connect6Move bestmove  = new Connect6Move(null, null);

            foreach (Connect6Move move in state.AllPossibleMoves())
            {
                double score = -GetBestMove(state.Apply(move)).Item2;
                if (score > bestscore)
                {
                    bestscore = score;
                    bestmove  = move;
                }
            }
            return(new Tuple <Connect6Move, double>(bestmove, bestscore));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// current  (0,1) (1,2)
        ///  m2 (1,2) (0,1)
        /// <param name="obj">The <see cref="object"/> to compare with the current <see cref="T:Connect6.Connect6Move"/>.</param>
        /// <returns><c>true</c> if the specified <see cref="object"/> is equal to the current
        /// <see cref="T:Connect6.Connect6Move"/>; otherwise, <c>false</c>.</returns>

        public override bool Equals(object obj)
        {
            if (obj is Connect6Move)
            {
                Connect6Move m2 = obj as Connect6Move;
                return(Pos1 == m2.Pos1 && Pos2 == m2.Pos2 || Pos1 == m2.Pos2 && Pos2 == m2.Pos1);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public static void PlayGame()
        {
            Player[,] board = new Player[, ] {
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty }
            };

            Connect6State state = new Connect6State(Player.White, board);

            Console.WriteLine("The Computer is White, You Are Black");
            while (!state.IsFinal())
            {
                Console.WriteLine("Current Player: " + state.currentPlayer);
                PrintBoard(board);
                if (state.currentPlayer == Player.White)
                {
                    Console.WriteLine("Calculating Move...");
                    Connect6Move move = GetBestMoveDepthLimited(state, 2).Item1;
                    state = state.Apply(move);
                }
                else
                {
                    Console.WriteLine("Choose A Row And A Column for position 1:");
                    int           row  = int.Parse(Console.ReadLine());
                    int           col  = int.Parse(Console.ReadLine());
                    BoardPosition pos1 = new BoardPosition(row, col);
                    Console.WriteLine("Choose A Row And A Column for position 2:");
                    int           row2 = int.Parse(Console.ReadLine());
                    int           col2 = int.Parse(Console.ReadLine());
                    BoardPosition pos2 = new BoardPosition(row2, col2);
                    Connect6Move  move = new Connect6Move(pos1, pos2);
                    state = state.Apply(move);
                }

                board = state.board;
            }

            PrintBoard(board);

            if (state.IsTied())
            {
                Console.WriteLine("Tied!");
            }
            else
            {
                Console.WriteLine("{0} Won!", state.currentPlayer.Next());
            }
        }
Ejemplo n.º 4
0
        ///////////Need to check

        public Connect6State Apply(Connect6Move move)
        {
            Player[,] newboard = CloneBoard();

            if (IsValid(move.Pos1) && IsValid(move.Pos2))
            {
                newboard[move.Pos1.Row, move.Pos1.Column] = currentPlayer;
                newboard[move.Pos2.Row, move.Pos2.Column] = currentPlayer;
            }

            Connect6State newstate = new Connect6State(currentPlayer.Next(), newboard);

            return(newstate);
        }
Ejemplo n.º 5
0
        public static void PlayGameComputer()
        {
            Player[,] board = new Player[, ] {
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty }
            };

            Connect6State state = new Connect6State(Player.White, board);

            while (!state.IsFinal())
            {
                Console.WriteLine("Current Player: " + state.currentPlayer);
                Console.WriteLine();
                PrintBoard(board);
                if (state.currentPlayer == Player.White)
                {
                    Console.WriteLine("Calculating Move...");
                    Console.WriteLine();
                    Connect6Move move = GetBestMoveDepthLimited(state, 2).Item1;
                    state = state.Apply(move);
                }
                else
                {
                    Console.WriteLine("Calculating Move...");
                    Console.WriteLine();
                    Connect6Move move = GetBestMoveDepthLimited(state, 2).Item1;
                    state = state.Apply(move);
                }

                board = state.board;
            }

            PrintBoard(board);
            if (state.IsTied())
            {
                Console.WriteLine("Tied!");
            }
            else
            {
                Console.WriteLine("{0} Won!", state.currentPlayer.Next());
            }
        }
Ejemplo n.º 6
0
        public List <Connect6Move> AllPossibleMoves()
        {
            List <BoardPosition> AllPositions = GetNonOccupiedPositions();
            List <Connect6Move>  AllMoves     = new List <Connect6Move>();

            if (AllPositions.Count == 1)
            {
                AllMoves.Add(new Connect6Move(AllPositions[0], AllPositions[0]));
            }
            foreach (BoardPosition pos1 in AllPositions)
            {
                foreach (BoardPosition pos2 in AllPositions)
                {
                    Connect6Move move = new Connect6Move(pos1, pos2);

                    if (pos1 != pos2 && !AllMoves.Contains(move))
                    {
                        AllMoves.Add(move);
                    }
                }
            }

            return(AllMoves);
        }