// {{{{{{{{ RUN SIMULATION }}}}}}}} private void Run_Click(object sender, System.EventArgs e) { NewGame(); ExecuteTimer.Start(); ExecuteTimer.Tick += Play; }
//被推动动画结束后执行回调 public void OnMoveEnd(Vector2 moveEndPosition) { ExecuteTimer.OnExecutePrepare(); //保存被推动后的坐标 _moveEndPosition = moveEndPosition; //递归检查 SearchAffectedBoxes(); //递归检查结束,所有box状态确定,下落坐标确定,可以下落 pushDropEvent(); ExecuteTimer.OnExecuteEnd(); print("sendCount =" + ReciveCount); ReciveCount = 0; }
public async void Play(object sender, EventArgs e) { ExecuteTimer.Stop(); //Globals.FailSafe = 1; //Force failsafe //Check for failsafe if (Globals.PlayerTurn == 0 || Globals.FailSafe == 1 || Globals.PlayerTurn > PlayersAmount.Maximum || PlayersAmount.Value == 0 || Globals.NotEnoughCards == 1) { GamesAmount.Value = GamesAmount.Minimum; DebugBox.Text = ""; Status.Text = "Status: Simulation Ended ----> Error (either the card distribution is wrong or memory is corrupted) check debug box"; DebugBox.AppendText("PlayerTurn ----> " + Globals.PlayerTurn + Environment.NewLine); if (Globals.FailSafe == 1) { DebugBox.AppendText("FailSafe is set to 1 ---> Try using a set seed." + Environment.NewLine); } if (Globals.PlayerTurn > PlayersAmount.Maximum) { DebugBox.AppendText("PlayerTurn > PlayersAmount.Maximum ----> Are you editing memory? Wrong value to edit" + Environment.NewLine); } if (PlayersAmount.Value == 0) { DebugBox.AppendText("PlayersAmount.Value == 0 ----> Are you editing memory? Wrong value to edit" + Environment.NewLine); } if (Globals.NotEnoughCards == 1) { DebugBox.AppendText("Globals.NotEnoughCards ----> You need to add more cards" + Environment.NewLine); } DebugBox.AppendText(Environment.NewLine + "Open an issue on my GitHub and paste this output if you don't know how to solve this issue"); } else { var watch = System.Diagnostics.Stopwatch.StartNew(); Status.Text = "Status: Running simulation..."; //var TempPlayerArray[] = //Alpha is the id of the game being simulated for (int alpha = 1; alpha <= GamesAmount.Value; alpha++) { NewGame(); //Set game to on Globals.isGameOn = true; //Used to check if player can play or not //var ALLOW_TURN_EDIT = 1; //Display current game in Main CurrentGameLabel.Text = "Current game: " + alpha + "/" + GamesAmount.Value; //While game is on // {{{{{{{{ NOTE: THIS IS BASICALLY THE BEGINNING OF THE AI }}}}}}}} while (Globals.isGameOn) { //Add a tiny-tiny delay await PutTaskDelay(1); //Reset personal flags Globals.DoIHaveSameColors = false; Globals.DoIHaveSameNumbers = false; Globals.DoIHaveSameID = false; Globals.DoIHaveWild = false; //Fix stepping, as it doesn't really work. if (Stepping.Checked) { SpinWait.SpinUntil(() => Globals.DebugWait == false, 50); //This can be used to slow down the calculation if (Globals.DebugWait == false) { Globals.DebugWait = true; Globals.isGameOn = false; } } /* * * We should consider a setting up a risk score first, then choose what to play based on that * * But before that, check who's playing next. * * */ // {{{{{{{{ EVALUATION }}}}}}}} // {{{{{{{{ WHO'S NEXT ? }}}}}}}} JObject rss = JObject.Parse(Globals.JsonGame); JObject game = rss["Game"] as JObject; //Who's playing next? // Json: Game --> Next_Player Globals.PlayerTurn = (int)rss["Game"]["Next_Player"]; if (Globals.Clockwise == true) { if (Globals.PlayerTurn + 1 > PlayersAmount.Value) { game["Next_Player"] = 1; Globals.PlayerTurn = 1; } else { game["Next_Player"] = Globals.PlayerTurn + 1; Globals.PlayerTurn = Globals.PlayerTurn + 1; } } else { if (Globals.PlayerTurn - 1 == 0) { game["Next_Player"] = PlayersAmount.Value; Globals.PlayerTurn = Convert.ToInt32(PlayersAmount.Value); } else { game["Next_Player"] = Globals.PlayerTurn - 1; Globals.PlayerTurn = Globals.PlayerTurn - 1; } } // {{{{{{{{ GET TOP CARD }}}}}}}} //Get top card Scoreboard.Text = Globals.JsonGame; //debug Globals.DoIHaveSameColors = false; Globals.DoIHaveSameID = false; //Get identity of deck (current player turn) JArray decks = (JArray)game["Player_Decks"][Globals.PlayerTurn.ToString()]; //Check if I have the same color string color_to_check = (string)rss["Game"]["TopCard_Color"]; for (int i = 0; i < decks.Count; i++) { if (Globals.DoIHaveSameColors == false && color_to_check == decks[i].ToString().Split('_').Last()) { //Set top card color //Top should be: 0_Green //Seed 0 --> Deck: Contains 1_Green. so it's true (last is 9_blue) Globals.DoIHaveSameColors = true; //Scoreboard.Text = "Top: "+color_to_check+ ", my: "+decks[i].ToString().Split('_').Last(); //debug } } //Check if I have the same id //It can be a number, trap, wild, ecc.. Same card ignoring color string id_to_check = (string)rss["Game"]["TopCard_ID"]; for (int i = 0; i < decks.Count; i++) { if (Globals.DoIHaveSameID == false && id_to_check == decks[i].ToString().Split('_').First()) { if (decks[i].ToString().Split('_').First() == "Wild") { Globals.DoIHaveWild = true; } Globals.DoIHaveSameID = true; } } /* Calculate end game * * -We can check if any player has no cards, that means someone has won * Better add this check after a placement/usage of card and then we set a flag or simply set "isGameOn" to true * */ //Atm I have no idea if the turn change works, as there's nothing that checks if a game must go on. //Once code gets executed here, game just ends (thinking of including a score check for "isGameOn") //Change turn //End of game if (Stepping.Checked == false) { Globals.isGameOn = false; } } } Status.Text = "Status: Simulation Ended"; // the code that you want to measure comes here watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; EmulationLabel.Text = "Emulation time taken: " + elapsedMs.ToString() + "ms"; } //END OF SIMULATION }