How to add buttons for playing against different bots (guide) #239
penguinsrepic
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I modified my UI a bit and thought that some people might want to do the same so I'm showing how here.
(My bot isn't very good, please ignore the winrate lol)
To add the winrate % all you do is go to the MatchStatsUI.cs file (Chess-Challenge/src/Framework/Application/UI/MatchStatsUI.cs)
and add something like
DrawNextText($"Winrate: {(float)stats.NumWins / (controller.CurrGameNumber - 1) * 100}%", regularFontSize, col);
in the DrawStats() function
For the buttons you go to the ChallengeController.cs file
(Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs)
and add whatever you want the name of the bot to be into the PlayerType enum.
Then go to the CreatePlayer() function and add
PlayerType.{whatever you put in the enum} => new ChessPlayer(new {the name of the bot's script}(), type, GameDurationMilliseconds),
That will create the PlayerType for your bot but you still need to create the buttons
Now you go to the MenuUI.cs file (Chess-Challenge/src/Framework/Application/UI/MenuUI.cs)
and add
buttonPos = UIHelper.Scale(new Vector2(405, 210)); buttonSize = UIHelper.Scale(new Vector2(200, 55)); if (NextButtonInRow("MyBot vs ExampleBot", ref buttonPos, spacing, buttonSize)) { controller.StartNewBotMatch(ChallengeController.PlayerType.MyBot, ChallengeController.PlayerType.{ExampleBot}); }
I added the code below all of the default menu buttons so I can change the buttonPos and ButtonSize variables without breaking anything.
For the buttons to not be overlapping I changed the buttonPos variable on line 12 to be
Vector2 buttonPos = UIHelper.Scale(new Vector2(150, 210));
instead of
Vector2 buttonPos = UIHelper.Scale(new Vector2(260, 210));
(which is the default)
I think that is everything in order to do these changes but if I forgot a step just tell me.
Beta Was this translation helpful? Give feedback.
All reactions