public void Verify_Assignment_Of_CellOwner(CellOwners assignedCellOwner) { // assign var ticTacToeCell = new TicTacToeCell(); // act and assert ticTacToeCell.CellOwner = assignedCellOwner; ticTacToeCell.CellOwner.ShouldBe(assignedCellOwner); }
public void Verify_Assignment_Of_CellOwner(CellOwners attemptedAssignment, CellOwners expectedResult) { // assign var ticTacToeCell = new TicTacToeCell(); // action ticTacToeCell.CellOwner = attemptedAssignment; // assert ticTacToeCell.CellOwner.ShouldBe(expectedResult); }
public void Verify_Assignment_Of_ColID(int attemptedAssignment, int expectedResult) { // assign var ticTacToeCell = new TicTacToeCell(); // action ticTacToeCell.ColID = attemptedAssignment; // assert ticTacToeCell.ColID.ShouldBe(expectedResult); }
public void Verify_Assignment_Of_RowID_And_ColID(int assignedRowID, int assignedColID) { // assign var ticTacToeCell = new TicTacToeCell(); // act and assert ticTacToeCell.RowID = assignedRowID; ticTacToeCell.RowID.ShouldBe(assignedRowID); ticTacToeCell.ColID = assignedColID; ticTacToeCell.ColID.ShouldBe(assignedColID); }
public void Assignment_Of_ColID_Outside_Range_Should_Fault(int attemptedAssignment) { // assign var ticTacToeCell = new TicTacToeCell(); // action // na // assert Should.Throw <ArgumentOutOfRangeException>(() => ticTacToeCell.ColID = attemptedAssignment); }
int GetCellIndex(TicTacToeCell cell) { for (int index = 0; index < cells.Length; index++) { if (cells[index] == cell) { return(index); } } return(-1); // Not found }
public void TicTacToeCell_Initializes_Properly() { // assign var ticTacToeCell = new TicTacToeCell(); // action // assert ticTacToeCell.RowID.ShouldBe(0); ticTacToeCell.ColID.ShouldBe(0); ticTacToeCell.CellOwner.ShouldBe(CellOwners.Open); }
public void Verify_TicTacToeCell_Instantiation() { // arrange var ticTacToeCell = new TicTacToeCell(); // act and assert ticTacToeCell.ShouldNotBeNull(); ticTacToeCell.ShouldBeOfType <TicTacToeCell>(); ticTacToeCell.CellOwner.ShouldBe(CellOwners.Open); ticTacToeCell.RowID.ShouldBe(0); ticTacToeCell.ColID.ShouldBe(0); }
void OnCellClicked(TicTacToeCell cell) { Debug.Log(GetCellIndex(cell)); TicTacToe.Node node = GenerateNodeFromBoard(); node.player = 1; if (miniMax.DoesGameFinish(node, ref result)) { return; } int cellIndexChosenByComputer = miniMax.MakeComputerDecision(node, maxSearchDepth); cells[cellIndexChosenByComputer].DisplayMark(TicTacToeCell.MarkType.X_MARK); node = GenerateNodeFromBoard(); if (miniMax.DoesGameFinish(node, ref result)) { return; } }
public void RunGame(object sender, EventArgs e) { HasWinner = false; IsUserTurn = startplayer.Checked; winnerlabel.Text = ""; Round = 0; TicTacToeDifficulty difficulty; if (easy.Checked) { difficulty = TicTacToeDifficulty.Easy; } else if (medium.Checked) { difficulty = TicTacToeDifficulty.Medium; } else { difficulty = TicTacToeDifficulty.Difficult; } AI = new TicTacToeAI(difficulty); Board = new TicTacToeCell[9]; for (int i = 0; i < 9; i++) { Board[i] = TicTacToeCell.None; } PrintBoard(Board); if (startai.Checked) { HandleAIInput(AI.ComputeNextMove(Board)); } }
private bool IsThreeInTheOtherDiagonal(TicTacToePlayer player, TicTacToeCell cell) => cell.Row + cell.Col == 2 && State.Cells[0, 2] == player && State.Cells[1, 1] == player && State.Cells[2, 0] == player;
private void MakeMove(TicTacToeCell cell) { Log.Instance.AddToAll(Player.Instance.PlayerSide.ToString() + " made move"); if (_activePlayer == Player.Instance.PlayerSide) { var pv = GetComponent<PhotonView>(); pv.RPC("SetCell", PhotonTargets.All, cell.row, cell.col); if (CheckWin(cell.row, cell.col) == false) { pv.RPC("EndTurn", PhotonTargets.All); } else { Log.Instance.AddToAll(Player.Instance.PlayerSide.ToString() + "win"); } } }
public TicTacToeCalculatedAction(TicTacToeCell cell, TicTacToeCalculatedActionType type) : base(cell) { ActionType = type; }
private bool IsOutOfBounds(TicTacToeCell cell) => cell.Row > 2 || cell.Col > 2;
/// <summary> /// Initializes a new instance of the <see cref="TicTacToeMove"/> class. /// </summary> /// <param name="player">The TicTacToe player.</param> /// <param name="cell">The TicTacToe cell being marked.</param> public TicTacToeMove(TicTacToePlayer player, TicTacToeCell cell) { Player = player; Cell = cell; }
private bool IsValidMove(TicTacToePlayer player, TicTacToeCell cell) => IsValidPlayer(player) && !IsGameFinished() && !IsOutOfBounds(cell) && !IsCellOccopied(cell);
private bool IsCellOccopied(TicTacToeCell cell) => State.Cells[cell.Row, cell.Col] != null;
private bool IsThreeInTheRow(TicTacToePlayer player, TicTacToeCell cell) => State.Cells[cell.Row, 0] == player && State.Cells[cell.Row, 1] == player && State.Cells[cell.Row, 2] == player;
private bool IsThreeInTheColumn(TicTacToePlayer player, TicTacToeCell cell) => State.Cells[0, cell.Col] == player && State.Cells[1, cell.Col] == player && State.Cells[2, cell.Col] == player;
private bool IsWinningMoveByPlayer(TicTacToePlayer player, TicTacToeCell cell) => IsThreeInTheRow(player, cell) || IsThreeInTheColumn(player, cell) || IsThreeInTheDiagonal(player, cell) || IsThreeInTheOtherDiagonal(player, cell);
void HandleWinScenario() { List <List <int> > combinations = new List <List <int> > { new List <int> { 0, 1, 2 }, new List <int> { 3, 4, 5 }, new List <int> { 6, 7, 8 }, new List <int> { 0, 3, 6 }, new List <int> { 1, 4, 7 }, new List <int> { 2, 5, 8 }, new List <int> { 0, 4, 8 }, new List <int> { 2, 4, 6 } }; TicTacToeCell winner = TicTacToeCell.None; foreach (List <int> l in combinations) { TicTacToeCell cw = CheckForWinner(Board, l); if (cw != TicTacToeCell.None) { winner = cw; } } if (winner == TicTacToeCell.AI) { HasWinner = true; winnerlabel.Text = "AI wins!"; int aipointsscore = int.Parse(aipoints.Text) + 1; aipoints.Text = aipointsscore.ToString(); } else if (winner == TicTacToeCell.User) { HasWinner = true; winnerlabel.Text = "User wins!"; int userscore = int.Parse(userpoints.Text) + 1; userpoints.Text = userscore.ToString(); } else if (winner == TicTacToeCell.None) { int c = 0; foreach (TicTacToeCell tttc in Board) { if (tttc != TicTacToeCell.None) { c++; } } if (c == 9) { HasWinner = true; winnerlabel.Text = "Draw!"; int draws = int.Parse(drawcount.Text) + 1; drawcount.Text = draws.ToString(); } } }
private bool IsThreeInTheDiagonal(TicTacToePlayer player, TicTacToeCell cell) => cell.Row == cell.Col && State.Cells[0, 0] == player && State.Cells[1, 1] == player && State.Cells[2, 2] == player;