Exemple #1
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // TODO:  Determine a winner has been reached.
                // return true if a winner has been reached.
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner()
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                if (a == b && a == c)
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                if ((a == "O" && b == "O" && c == "O") || (a == "X" && b == "X" && c == "X"))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // TODO:  Determine a winner has been reached.
                // return true if a winnerj has been reached.

                if (a == b && b == c)
                {
                    return(true);
                }
                //player 1 choose number
                //verify the number is available and not taken, change the location to marker
                //switch player
                //have player 2 select
                //verify
                //switch player
                //check for winner or draw every loop


                //IM STUCK i have been struggling with this all day today i cannot make snese of this.
                //got help from chris
            }

            return(false);
        }
Exemple #5
0
        public void Player_input_matches_index(int value, int expectedRow, int expectedCol)
        {
            // Arrange
            Player player1 = new Player();
            Player player2 = new Player();


            // Act
            Position actual = Player.PositionForNumber(value);



            // Assert
            Assert.NotNull(actual);
            Assert.Equal(expectedRow, actual.Row);
            Assert.Equal(expectedCol, actual.Column);
        }
Exemple #6
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);
                // if statement to check contents of abc strings against winners array - match bool to true
                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];


                // TODO:  Determine a winner has been reached.
                // if statement to compare a to b and maybe b to c???
                // return true if a winner has been reached.
                if (a == "X" && b == "X" && c == "X")
                {
                    Console.WriteLine("Player One Wins");
                    return(true);
                }
                else if (a == "O" && b == "O" && c == "O")
                {
                    Console.WriteLine("Player Two Wins");
                    return(true);
                }
            }

            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                //shows winning positions by number
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            bool answer = false;

            for (int i = 0; i < winners.Length; i++)
            {
                //creates postion objects for showing winning positions by row and col
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                //grabs the numerical position(or the entry?) using the row and cols as indices..
                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                if (a == b && b == c)
                {
                    answer = true;
                    break;
                }
                else
                {
                    answer = false;
                }
            }

            return(answer);
        }
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // TODO:  Determine a winner has been reached.
                // return true if a winner has been reached.

                // checks to see if player 1 has three in a row
                if (a == "X" && b == "X" && c == "X")
                {
                    return(true);
                }
                // Checks to see if player 2 has three in a row
                else if (a == "O" && b == "O" && c == "O")
                {
                    return(true);
                }
            }
            // neither player has 3 in a row
            return(false);
        }
Exemple #9
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                //horizontal winning lines
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                //vertical winning lines
                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                //diagonal winning lines
                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                //assign the coordinates of positions 1, 2, & 3
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                //assign strings a, b, c as either an integer OR the marker that has replaced it
                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // TODO:  Determine a winner has been reached.
                // return true if a winner has been reached.
                // if all three positions are the same (either all x's or all o's)
                if (a == b && b == c && a == c)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #10
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // TODO:  Determine a winner has been reached.
                // return true if a winner has been reached.

                //I don't want to study the logic detail behind this
                //so I guessed what you were trying to do
                if ((a == b) && (b == c) && (a == c))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #11
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner()
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // TODO:  Determine a winner has been reached.
                // return true if a winner has been reached.

                //we need if statements, checking who wins
                if (a == b && b == c)
                {
                    Console.WriteLine("winner winner chicken dinner: ");
                    return(true);
                }
            }

            return(false);
        }
Exemple #12
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                //julie: 1-11-19 this returns the value in the "gameboard cell" ie at 0,0 a = 1
                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                //Console.WriteLine($"{i}: a {a} b {b} c {c}");
                // TODO:  Determine a winner has been reached.
                // return true if a winner has been reached.
                if (a == b && b == c && c == a)
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Check if winner exists on the current board state.
        /// </summary>
        /// <param name="board">Current state of the board</param>
        /// <returns>bool represneting if a winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                //Win by filling a row
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                //Or by filling a column
                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                //Or by filling a diagonal
                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                //needs to be board.GameBoard not Board.GameBoard
                string a = board.GameBoard[p1.Row, p1.Column];
                string b = board.GameBoard[p2.Row, p2.Column];
                string c = board.GameBoard[p3.Row, p3.Column];

                if (a == b && b == c)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #14
0
        /// <summary>
        /// Check if winner exists
        /// </summary>
        /// <param name="board">current state of the board</param>
        /// <returns>if winner exists</returns>
        public bool CheckForWinner(Board board)
        {
            int[][] winners = new int[][]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
                new[] { 7, 8, 9 },

                new[] { 1, 4, 7 },
                new[] { 2, 5, 8 },
                new[] { 3, 6, 9 },

                new[] { 1, 5, 9 },
                new[] { 3, 5, 7 }
            };

            // Given all the winning conditions, Determine the winning logic.
            for (int i = 0; i < winners.Length; i++)
            {
                Position p1 = Player.PositionForNumber(winners[i][0]);
                Position p2 = Player.PositionForNumber(winners[i][1]);
                Position p3 = Player.PositionForNumber(winners[i][2]);

                string a = Board.GameBoard[p1.Row, p1.Column];
                string b = Board.GameBoard[p2.Row, p2.Column];
                string c = Board.GameBoard[p3.Row, p3.Column];

                // Checks the possible winning positions for the current player's markers.
                // Returns true if all three positions are occupied by their markers, i.e. the player has won the game.
                if (a == b && a == c)
                {
                    return(true);
                }
            }

            return(false);
        }