static void Main(string[] args) { //Prepare Operating-system independent environment and initialize some variables _winner = Winner.undetermined; if (PlatformID.Win32NT == Environment.OSVersion.Platform) { Console.WindowWidth = 100; } else { Console.WriteLine("Please make sure that your Terminal Window is at least 100 characters wide"); Console.WriteLine("Press any key to cotinue when ready..."); Console.ReadKey(); } Console.ForegroundColor = ConsoleColor.Gray; //Create and initialize playing grids in which each player can see their own ships HomeGrid playerHomeGrid = new HomeGrid(Playertype.Human); HomeGrid aiHomeGrid = new HomeGrid(Playertype.AI); //Create and initialize radar Grids in which each player can EnemyGrid playerEnemyGrid = new EnemyGrid(Playertype.Human); EnemyGrid AIEnemyGrid = new EnemyGrid(Playertype.AI); //fleet deployment (currently automatic) Fleet playerFleet = new Fleet(); Fleet aiFleet = new Fleet(); playerHomeGrid.DeployFleet(playerFleet); aiHomeGrid.DeployFleet(aiFleet); bool forfeit=false; // subscribe to fire-exchange events playerEnemyGrid.AimFireEvent += aiHomeGrid.ReceiveShot; AIEnemyGrid.AimFireEvent += playerHomeGrid.ReceiveShot; //Main game phase do { forfeit = playerEnemyGrid.AimAndFire(); if (Winner == Winner.undetermined && !forfeit) AI.Turn(AIEnemyGrid); } while (Winner == Winner.undetermined && !forfeit); //End of the game Console.SetCursorPosition(0, 23); if (forfeit) { Console.WriteLine("AI has won by player forfeiture"); } else { Console.WriteLine("Game ends. {0} victorious!", _winner.ToString()); } Console.ReadLine(); }
public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(base.ToString()); stringBuilder.Append(Environment.NewLine); stringBuilder.Append($"[Winner:{Winner.ToString()}"); return(stringBuilder.ToString()); }
public override string ToString() { return("Player name: " + PlayerName + "\n" + "Player symbol: " + Winner.ToString() + "\n" + "Win count: " + WinCount + "\n" + "Loss count: " + LossCount + "\n" + "Draw count: " + DrawCount + "\n" + "Fastest Game Time: " + (FastestGameTime == int.MaxValue ? "Not set" : FastestGameTime.ToString())); }
/// <summary> /// Converts this match into its XML representation. /// </summary> /// <param name="writer"></param> void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer) { writer.WriteAttributeString("ID", ID.ToString()); writer.WriteAttributeString("Location", Location); writer.WriteAttributeString("LogLevel", LogLevel.ToString()); writer.WriteAttributeString("Surface", MatchSurface.ToString()); writer.WriteAttributeString("Type", Type.ToString()); //Rules writer.WriteStartElement("Rules"); writer.WriteAttributeString("BestOutOf", BestOutOf.ToString()); writer.WriteAttributeString("DeuceSuddenDeath", DeuceSuddenDeath.ToString()); writer.WriteAttributeString("FinalSetIsTiebreak", FinalSetIsTiebreak.ToString()); writer.WriteAttributeString("FinalSetTieBreakLength", FinalSetTieBreakLength.ToString()); writer.WriteAttributeString("NumberGamesPerSet", NumberGamesPerSet.ToString()); writer.WriteAttributeString("TieBreakAtSameScoreOf", TieBreakAtSameScoreOf.ToString()); writer.WriteAttributeString("TieBreakFinalSet", TieBreakFinalSet.ToString()); writer.WriteAttributeString("TieBreakLength", TieBreakLength.ToString()); writer.WriteEndElement(); //Status writer.WriteStartElement("Status"); writer.WriteAttributeString("NextContestantToServe", NextContestantToServe.ContestantNr.ToString()); writer.WriteAttributeString("Status", Status.ToString()); writer.WriteAttributeString("Winner", Winner.ToString()); writer.WriteEndElement(); //Contestants writer.WriteStartElement("Contestant1"); Contestant1.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("Contestant2"); Contestant2.WriteXml(writer); writer.WriteEndElement(); //Duration writer.WriteStartElement("Duration"); Duration.WriteXml(writer); writer.WriteEndElement(); //Statistics writer.WriteStartElement("Statistics"); Statistics.WriteXml(writer); writer.WriteEndElement(); //Sets writer.WriteStartElement("Sets"); foreach (var item in Sets) { item.WriteXml(writer); } writer.WriteEndElement(); }
private void buttonRace_Click(object sender, EventArgs e) { bool GameOver = false; char Winner; while (!GameOver) { foreach (var dog in GreyhoundArray) { if (dog.Run() == false) { dog.Run(); } else { Winner = dog.MyPictureBox.Name.ToString().Last(); string winners = Winner.ToString(); MessageBox.Show("Winner is dog # " + winners); int winnest = Convert.ToInt16(Winner.ToString()); //int WinningDog = Convert.ToInt16(Winner); Console.WriteLine("The winning dog is " + Winner); Console.WriteLine("The winnest dog is " + winnest); GameOver = true; foreach (var dude in GuyArray) { dude.MyBet.Payout(winnest); Console.WriteLine("The guy: " + dude.Name + "\n" + "Bet Amount: " + dude.MyBet.Amount + "\n" + "Dog bet On: " + dude.MyBet.Dog + "\n" + "The winner is: Dog#" + winnest); int amount = dude.MyBet.Payout(winnest); Console.WriteLine("This is the amount for winnings: " + amount); dude.cash = dude.cash += dude.MyBet.Payout(winnest); //MessageBox.Show(dude.MyBet.IsWinner((int)Winner)); //dude.Collect(dude.MyBet.Dog); dude.UpdateLabels(); dude.ClearBet(); } foreach (var pup in GreyhoundArray) { pup.TakeStartingPosition(); } } } } }
internal void OutputConstituencyVotingIntention(bool allPercentages) { if (constituency.ActualWinner == Party.None) { Console.WriteLine($"Constituency: {location}. Winner: {Winner.ToString()}"); } else { Console.WriteLine($"Constituency: {location}. Winner: {Winner.ToString()}. Actual:{constituency.ActualWinner} {(IsDifferent ? "**DIFFERENT**" : "")}"); } if (allPercentages) { OutputVotingPercentages(Intentions); } Console.WriteLine(); }
//공격・방어 애니메이션 연출 대기. void UpdateEndAction() { GameObject obj = GameObject.Find("ActionController"); if (obj == null) { //연출용 오브젝트가 없으면 생성합니다(이 시퀀스의 초기 동작입니다). obj = Instantiate(m_actionControllerPrefab) as GameObject; obj.name = "ActionController"; //연출을 위해 승패 판정을 합니다. InputData serverPlayer = m_inputData[0]; InputData clientPlayer = m_inputData[1]; //가위바위보 판정. Winner rpsWinner = ResultChecker.GetRPSWinner(serverPlayer.rpsKind, clientPlayer.rpsKind); //공방 속도 판정. m_actionWinner = ResultChecker.GetActionWinner(serverPlayer.attackInfo, clientPlayer.attackInfo, rpsWinner); Debug.Log("RPS Winner:" + rpsWinner.ToString() + " ActionWinner" + m_actionWinner.ToString()); //연출 시작. obj.GetComponent <ActionController>().Setup( m_actionWinner, m_score[0], m_score[1] ); return; } //전투 연출이 끝나길 기다립니다. ActionController actionController = obj.GetComponent <ActionController>(); if (actionController.IsEnd()) { //뒷처리. Destroy(GameObject.Find("BattleSelect")); //공수선택 표시물을 지운다. Destroy(GameObject.Find("ActionController")); //연출 제어를 제거. //m_timer = 0.0f; m_gameState = GameState.Result; } }
public override void Solve() { var pparser = new Pparser(FpatIn); rgx = pparser.Fetch <int[]>(); rgc = pparser.Fetch <int[]>(); rgGoalA = pparser.Fetch <int[]>(); rgGoalB = pparser.Fetch <int[]>(); time = 7; Winner winner = Winner.Nil; while (winner == Winner.Nil) { winner = Step(); } string result = winner.ToString() + " wins at " + time.ToString() + "."; using (Output) Solwrt.WriteLine(result); }
//공격・방어 애니메이션 연출 대기. void UpdateEndAction() { GameObject obj = GameObject.Find("ActionController"); if (obj == null) { //연출용 오브젝트가 없으면 생성합니다(이 시퀀스의 초기 동작입니다). obj = Instantiate(m_actionControllerPrefab) as GameObject; obj.name = "ActionController"; //연출을 위해 승패 판정을 합니다. InputData serverPlayer = m_inputData[0]; InputData clientPlayer = m_inputData[1]; //가위바위보 판정. Winner rpsWinner = ResultChecker.GetRPSWinner(serverPlayer.rpsKind, clientPlayer.rpsKind); //공방 속도 판정. m_actionWinner = ResultChecker.GetActionWinner(serverPlayer.attackInfo, clientPlayer.attackInfo, rpsWinner); Debug.Log("RPS Winner:" + rpsWinner.ToString() + " ActionWinner" + m_actionWinner.ToString()); //연출 시작. obj.GetComponent<ActionController>().Setup( m_actionWinner, m_score[0], m_score[1] ); return; } //전투 연출이 끝나길 기다립니다. ActionController actionController = obj.GetComponent<ActionController>(); if (actionController.IsEnd()) { //뒷처리. Destroy(GameObject.Find("BattleSelect")); //공수선택 표시물을 지운다. Destroy(GameObject.Find("ActionController")); //연출 제어를 제거. //m_timer = 0.0f; m_gameState = GameState.Result; } }
public override string ToString() { return(Winner.ToString()); }
public override string ToString() { return("Winner: " + Winner.ToString() + " Loser: " + Loser.ToString()); //return this._loby.Name; }
/// <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); }
// 가위바위보 결과와 공격/방어에서 승패를 구합니다. public static Winner GetActionWinner(AttackInfo server, AttackInfo client, Winner rpsWinner) { string debugStr = "rpsWinner:" + rpsWinner.ToString(); debugStr += " server.actionKind:" + server.actionKind.ToString() + " time:" + server.actionTime.ToString(); debugStr += " client.actionKind:" + client.actionKind.ToString() + " time:" + client.actionTime.ToString(); Debug.Log(debugStr); ActionKind serverAction = server.actionKind; ActionKind clientAction = client.actionKind; // 공격/방어가 바르게 이루어졌는지 판정합니다. switch (rpsWinner) { case Winner.ServerPlayer: if (serverAction != ActionKind.Attack) { // 1P가 공격을 하지 않았으므로 무승부. return Winner.Draw; } else if (clientAction != ActionKind.Block) { // 2P가 틀렸으므로 1P 승리. return Winner.ServerPlayer; } // 決着は시간이 됩니다. break; case Winner.ClientPlayer: if (clientAction != ActionKind.Attack) { // 2P가 공격을 하지 않았으므로 무승부.. return Winner.Draw; } else if (serverAction != ActionKind.Block) { // 1P가 틀렸으므로 2P가 승리합니다. return Winner.ClientPlayer; } // 決着は시간이 됩니다. break; case Winner.Draw: //무승부일 때는 무엇을 해도 무승부입니다. return Winner.Draw; } // 시간 대결. float serverTime = server.actionTime; float clientTime = client.actionTime; if (serverAction == ActionKind.Attack) { // 1P가 공격인 경우는 2P보다 빠를 때 이기게 됩니다. if (serverTime < clientTime) { // 1P 쪽이 빠르므로 승리입니다. return Winner.ServerPlayer; } } else { // 2P가 공격인 경우는 2P보다도 빠르게 방어하지 않으면 패배입니다. if (serverTime > clientTime) { return Winner.ClientPlayer; } } // 같은 시간이므로 무승부입니다. return Winner.Draw; }
// 가위바위보 결과와 공격/방어에서 승패를 구합니다. public static Winner GetActionWinner(AttackInfo server, AttackInfo client, Winner rpsWinner) { string debugStr = "rpsWinner:" + rpsWinner.ToString(); debugStr += " server.actionKind:" + server.actionKind.ToString() + " time:" + server.actionTime.ToString(); debugStr += " client.actionKind:" + client.actionKind.ToString() + " time:" + client.actionTime.ToString(); Debug.Log(debugStr); ActionKind serverAction = server.actionKind; ActionKind clientAction = client.actionKind; // 공격/방어가 바르게 이루어졌는지 판정합니다. switch (rpsWinner) { case Winner.ServerPlayer: if (serverAction != ActionKind.Attack) { // 1P가 공격을 하지 않았으므로 무승부. return(Winner.Draw); } else if (clientAction != ActionKind.Block) { // 2P가 틀렸으므로 1P 승리. return(Winner.ServerPlayer); } // 決着は시간이 됩니다. break; case Winner.ClientPlayer: if (clientAction != ActionKind.Attack) { // 2P가 공격을 하지 않았으므로 무승부.. return(Winner.Draw); } else if (serverAction != ActionKind.Block) { // 1P가 틀렸으므로 2P가 승리합니다. return(Winner.ClientPlayer); } // 決着は시간이 됩니다. break; case Winner.Draw: //무승부일 때는 무엇을 해도 무승부입니다. return(Winner.Draw); } // 시간 대결. float serverTime = server.actionTime; float clientTime = client.actionTime; if (serverAction == ActionKind.Attack) { // 1P가 공격인 경우는 2P보다 빠를 때 이기게 됩니다. if (serverTime < clientTime) { // 1P 쪽이 빠르므로 승리입니다. return(Winner.ServerPlayer); } } else { // 2P가 공격인 경우는 2P보다도 빠르게 방어하지 않으면 패배입니다. if (serverTime > clientTime) { return(Winner.ClientPlayer); } } // 같은 시간이므로 무승부입니다. return(Winner.Draw); }
private void gameController_OnGameEnd(object sender, Winner w) { _gameEnd.text = w.ToString() + " Win !!!"; mainMenu.SetActive(true); }