viewsgogl.blogg.se

Peg solitaire java code
Peg solitaire java code




  1. #PEG SOLITAIRE JAVA CODE CODE#
  2. #PEG SOLITAIRE JAVA CODE SIMULATOR#

It’s clear from the earlier tests that the first position is at a big disadvantage regardless of the strategy they use. Presumably, this is to help the first player overcome their positional disadvantage. In some versions of a white elephant party the first player is able to play again once all players have a gift. How much does allowing the first player to go again matter? However, in the later stage of the game, the same strategy can yield a 2.2X improvement. There’s only so much you can do in the early stages as a player’s options are limited.įor example, a player stealing above the mean can only improve their gift value by a factor of 1.7X during the early stage of the game compared to just always opening a gift. It appears that the strategy used has the most impact in the later stages of the game. Average gift value based on strategy used at different game stages The image below shows the average gift value based on algorithm and game stage. For example, if the NUM_OF_PLAYERS = 21, then the early stage is rounds [0, 7), mid stage is [7, 14), and late stage is [14, 21). Stages are evenly distributed across the total number of rounds/players. Taking this idea further, I looked at the impact strategies have on different stages of the game: early, mid, and late. This levels out a bit through the middle point of the game and then goes up again during the final selections.įirst 10 players using optimal strategy, second 10 using coin flip strategy Clearly, there’s a huge disadvantage to choosing early. If you look at the graph below, the y-axis represents the average gift value players received after 100,000 simulated games. Long story short, yes, yes it most certainly does. The first test I ran was to answer the question does the order you select a gift matter? Does order matter? For all tests, unless otherwise specified, I assumed there were 20 people playing, I used a maximum of 3 gift steals per gift, and I ran 100,000 games to compute the averages. YankeeSwap yankeeSwap = new YankeeSwap(players, gifts, maxSteals, letPlayerOneGoAgain) Setup game with players, gifts, and rules List players = initPlayers(totalPlayers) Run game simulationįor(int i = 0 i gifts = initGifts(totalPlayers)

#PEG SOLITAIRE JAVA CODE CODE#

You can see the Java code for this below or the exact implementation here. Then the game is plays out M times, keeping track of positional and algorithmic performance.

#PEG SOLITAIRE JAVA CODE SIMULATOR#

For each player, the simulator assigns a randomly selected strategy. For each gift, the simulator assigns a random gift value between 0 and 1. The simulator creates N players and N gifts. All players are trying to optimize the value of the gift they receive.I’m assuming that all players perceive the value of a gift the same.Otherwise apply the always steal strategy. Optimize for no steals – Based on the current mean value of opened gifts with MAX_STEALS – 1 steals, take the gift with the highest value above the mean.This article was the inspiration for this strategy. Steal based on mean – Based on the current mean value of opened gifts, steal the highest value item that is above the mean.Steal on coin flip – The player flips a coin and if it’s tails, they steal the highest value opened item.If no gifts are available, then open a random gift. Always steal – The player always steals an already opened gift with the highest value.They just want to open gifts and don’t really care what’s available to steal.

peg solitaire java code

Additionally, I feel like I’ve played with people that take this approach. This strategy is not likely to perform well given that the player isn’t really optimizing for anything, but it helps set a baseline for comparison.

  • Always open a gift – The player always opens a random gift if there is one available.
  • The simulator I wrote tests five different strategies: Optionally, I also considered the game rule where the first player to go gets an extra turn at the end of the game.
  • A gift can be stolen only up to a maximum number of times.
  • Within one round, a gift can’t be stolen twice.
  • If they steal, the person they stole from has the same options.
  • Each round a player can choose to open a new gift or steal a gift.
  • Players gift selection position in the game is random.
  • There are N players and each brings a gift.
  • For the purposes of the simulation code I wrote, I assumed the following game rules. There are lots of different game configurations for white elephant gift parties and the rules can have a major impact on the probability of getting a good gift depending on your position and strategy. To answer these deep philosophical questions, I wrote a gift exchange simulator to test different strategies against each other as well as help me answer some of these other troubling questions.Ĭheck out my analysis and answers below.






    Peg solitaire java code