/// <summary> /// Move quality /// -1 worst move /// 0 illegal move /// +1 best move /// </summary> public static int MoveQuality(this TicTacToePosition position, TicTacToeLocation move) { if (position is null) { return(0); } if (move is null) { return(0); } var actual = MoveExpectation(position, move); if (actual == GameOutcome.Illegal) { return(0); } var best = ExpectedWinner(position); if (best == actual) { return(1); } else { return(-1); } }
/// <summary> /// Move Degree, winning, loosing etc. /// </summary> public static MoveExpectancy MoveDegree(this TicTacToePosition position, TicTacToeLocation move) { if (position is null) { return(MoveExpectancy.Illegal); } if (move is null) { return(MoveExpectancy.Illegal); } if (!position.IsLegalMove(move, true)) { return(MoveExpectancy.Illegal); } var expectation = MoveExpectation(position, move); if (expectation == GameOutcome.Illegal) { return(MoveExpectancy.Illegal); } if (position.WhoIsOnMove == Mark.Cross) { if (expectation == GameOutcome.FirstWin) { return(MoveExpectancy.Win); } else if (expectation == GameOutcome.Draw) { return(MoveExpectancy.Draw); } else if (expectation == GameOutcome.SecondWin) { return(MoveExpectancy.Lose); } } else { if (expectation == GameOutcome.FirstWin) { return(MoveExpectancy.Lose); } else if (expectation == GameOutcome.Draw) { return(MoveExpectancy.Draw); } else if (expectation == GameOutcome.SecondWin) { return(MoveExpectancy.Win); } } return(MoveExpectancy.Illegal); }
/// <summary> /// Move Expectation /// </summary> public static GameOutcome MoveExpectation(this TicTacToePosition position, TicTacToeLocation move) { if (position is null) { return(GameOutcome.Illegal); } if (move is null) { return(GameOutcome.Illegal); } return(ExpectedWinner(position.MakeMove(move))); }
/// <summary> /// Is Move Legal /// </summary> public bool IsLegalMove(TicTacToeLocation move, bool checkForOutcome) { if (move is null) { return(false); } if (m_Marks[move.Index - 1] != Mark.None) { return(false); } if (checkForOutcome && Outcome != GameOutcome.None) { return(false); } return(true); }
/// <summary> /// Make Move /// </summary> public TicTacToePosition MakeMove(TicTacToeLocation move) { if (move is null) { throw new ArgumentNullException(nameof(move)); } if (m_Marks[move.Index - 1] != Mark.None) { throw new InvalidOperationException("Illegal move"); } if (Outcome != GameOutcome.None) { throw new InvalidOperationException("The game is over"); } TicTacToePosition result = Clone(); result.m_Marks[move.Index - 1] = WhoIsOnMove; return(result); }
/// <summary> /// Board /// </summary> /// <param name="line">Line</param> /// <param name="column">Column</param> /// <returns>Mark</returns> public Mark this[TicTacToeLocation move] { get => move is null
/// <summary> /// Is Move Legal /// </summary> public bool IsLegalMove(TicTacToeLocation move) => IsLegalMove(move, true);