示例#1
0
        // 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();
                }
            }
        }
    // Method for invoking the MatchOver event
    private void OnMatchOver()
    {
        // Send a message to the UI with the match result
        view.SubmitMessage(string.Format("Game Over, {0}",
                                         Result == Winner.Draw
                ? "it's a draw"
                : $"{PlrNameColor(Result.ToPColor())} won"));

        // Set internal matchOver variable to true; this will stop further
        // Update()s
        matchOver = true;

        // Notify MatchOver listeners
        MatchOver?.Invoke();
    }
 public void ToPColor_CorrectPColor_No(Winner winner, PColor color)
 {
     Assert.NotEqual(color, winner.ToPColor());
 }
        /// <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);
        }