// Renders the match over screen, showing the final result private void MatchOver( Winner winner, ICollection <Pos> solution, IList <string> thinkerNames) { // Did the match end in a draw? if (winner == Winner.Draw) { // If so, show that information Console.WriteLine("Game ended in a draw"); } else { // Otherwise, show match results PColor winnerColor = winner.ToPColor(); int winnerIdx = (int)winnerColor; string winnerName = thinkerNames[winnerIdx]; // Show who won Console.WriteLine( $"Winner is {winnerColor.FormatName(winnerName)}"); // Show the solution, if available if (solution != null) { Console.Write("Solution="); foreach (Pos pos in solution) { Console.Write(pos); } Console.WriteLine(); } } }
public void FormatName_ShouldContainColor_Always( PColor color, string name) { string formatedName = color.FormatName(name); Assert.Contains(color.ToString(), formatedName); }
// Displays the move performed by the specified thinker private void MovePerformed( PColor thinkerColor, string thinkerName, FutureMove move, int thinkingTime) { Console.WriteLine(thinkerColor.FormatName(thinkerName) + $" placed a {move.shape} piece at column {move.column}" + $" after {thinkingTime}ms"); }
/// <summary>Name and color of given player.</summary> /// <param name="color">Color of player to get name/color of.</param> /// <returns>A string with the name and color of player.</returns> public string PlrNameColor(PColor color) => color.FormatName(matchData.GetThinker(color).ToString());
// Displays notification that the specified thinker lost due to an // invalid play private void InvalidMove( PColor thinkerColor, string thinkerName, string reason) { Console.WriteLine(String.Format("{0} loses match! Reason: {1}", thinkerColor.FormatName(thinkerName), reason)); }
// Renders info about the next turn private void NextTurn(PColor thinkerColor, string thinkerName) { Console.WriteLine($"{thinkerColor.FormatName(thinkerName)} turn"); }
/// <summary> /// Run a session of ColorShapeLinks matches. /// </summary> /// <param name="complete"> /// Is the session complete, i.e., should thinkers compete against each /// other two times, home and away? /// </param> /// <returns> /// An exit status according to what is defined in /// <see cref="ExitStatus"/>. /// </returns> public ExitStatus Run(bool complete) { // The exit status ExitStatus exitStatus = default; // Create a new session (the model in MVC) session = new Session(thinkerPrototypes, sessionConfig, complete); // Notify listeners that session is about to start BeforeSession?.Invoke(this); // Play each match defined by the session while (session.NextMatch(out currentMatch)) { // Create a new board for the current match board = new Board(matchConfig.Rows, matchConfig.Cols, matchConfig.WinSequence, matchConfig.RoundPiecesPerPlayer, matchConfig.SquarePiecesPerPlayer); // Instantiate thinkers for the current match currentThinkers[(int)PColor.White] = currentMatch.thinkerWhite.Create(); currentThinkers[(int)PColor.Red] = currentMatch.thinkerRed.Create(); // Add registered listeners to the thinker instances foreach (IThinkerListener listener in thinkerListeners) { foreach (IThinker thinker in currentThinkers) { listener.ListenTo(thinker); } } // Create a match controller for the current match MatchController mc = new MatchController(matchConfig, this); // Register match listeners with the match controller foreach (IMatchListener listener in matchListeners) { listener.ListenTo(mc); } // Notify listeners that a match is about to start BeforeMatch?.Invoke(currentMatch); // Ask the controller to run the match and keep the result lastMatchResult = mc.Run(); // Update variables and properties related to the match result exitStatus = lastMatchResult.ToExitStatus(); // Update the winner string if (lastMatchResult != Winner.Draw) { PColor winnerColor = lastMatchResult.ToPColor(); WinnerString = winnerColor.FormatName( currentThinkers[(int)winnerColor].ToString()); } else { WinnerString = lastMatchResult.ToString(); } // Notify result to session session.SetResult(lastMatchResult); // Notify listeners that a match is over AfterMatch?.Invoke(currentMatch, this); } // Notify listeners that sessions is about to end AfterSession?.Invoke(this); // The exit status will either be for a complete session of // associated with the match result return(complete ? ExitStatus.Session : exitStatus); }