In a little minigame I'm making there are two NPC's which I have coded to shoot and kill one another when I press their corresponding keys. The game works great but there is a bit of a bias. When both NPCs shoot at eachother during the same tick then the code checks which bullet collided with which NPC first... Problem is that the code is written so it always checks if NPC(0) was shot first. Since there are two simultaneous collisions but NPC(0) is checked first then NPC(0) dies and NPC(1) wins the game. This is not fair though...
Can someone suggest a way to remove this bias? I was thinking of implementing a code that checks for "ties" maybe. Or is there a way to more finely measure who was shot first?
How can I get rid of bias in my code?
Moderators: marionline, SDHawk
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
How can I get rid of bias in my code?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- Taco Bot
- Meat, Cheese, and Silicon
- Posts: 484
- Joined: Fri Jul 18, 2014 12:15 am
- Location: Santa Cruz
- Contact:
Re: How can I get rid of bias in my code?
Maybe you could make a random generator which decides which checks first?
Sent from my iPhone
One way to eliminate the bias would be to not kill the NPCs immediately, but "mark" them somehow as killed and wait until all of the collisions have been checked and all of the "killed" npcs marked before deciding who wins and who loses. That way you could see if both guys have been shot at the same time.
- Urkelbot666
- Slime Knight
- Posts: 188
- Joined: Sat Oct 18, 2014 5:29 pm
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
This sounds good. Then I could just implement a "tie" and make it so neither player gains a point.Gizmog wrote:One way to eliminate the bias would be to not kill the NPCs immediately, but "mark" them somehow as killed and wait until all of the collisions have been checked and all of the "killed" npcs marked before deciding who wins and who loses. That way you could see if both guys have been shot at the same time.
Thanks for all the responses. Sorry I didn't clarify what I wanted, I just wanted to see he various different things people could come up with to solve this to make sure there wasn't anything I overlooked.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- Spoonweaver
- Liquid Metal King Slime
- Posts: 6467
- Joined: Mon Dec 08, 2008 7:07 am
- Contact:
What I would do is make a variable, let's call it 'tiebreaker'.
Then, at the beginning of your script loop, set tiebreaker to 0.
When you check collisions, if it's true on player 1, tiebreaker:=tiebreaker+1
if it's true on player 1, tiebreaker:=tiebreaker+2
then at the end of the loop, check your tiebreaker variable
if it's 1, player one hits
if it's 2, player two hits
if it's added up to 3, tie
Then, at the beginning of your script loop, set tiebreaker to 0.
When you check collisions, if it's true on player 1, tiebreaker:=tiebreaker+1
if it's true on player 1, tiebreaker:=tiebreaker+2
then at the end of the loop, check your tiebreaker variable
if it's 1, player one hits
if it's 2, player two hits
if it's added up to 3, tie
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
I went with this in the end. Seemed like the simplest fix. Works great too. It's actually quite hard to time the shots perfectly for the players to get a tie. I just didn't want one player to be at an advantage.Spoonweaver wrote:What I would do is make a variable, let's call it 'tiebreaker'.
Then, at the beginning of your script loop, set tiebreaker to 0.
When you check collisions, if it's true on player 1, tiebreaker:=tiebreaker+1
if it's true on player 1, tiebreaker:=tiebreaker+2
then at the end of the loop, check your tiebreaker variable
if it's 1, player one hits
if it's 2, player two hits
if it's added up to 3, tie
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases