Playing a game of Risk with GPT-4

This will likely be a long thread but I’ve been teaching GPT-4 to play the boardgame Risk and thought I’d share my observations and learnings with the community…

I’ll jump in largely at the beginning of our game but even before playing the first turn I’ve learned a lot about GPT-4. I got it to define all the variables needed to track the game state and it did a good job of that. I then asked it to setup a two player game and randomly deploy each players troops to those territories. I’d say it did an ok job at that but I find it super interesting that it tended to give both the Human and AI player whole countries and it gave the AI player Asia… We know how that typically works out. I got America, Australia, and Africa so even though it has more starting territories I think we can all agree its screwed :slight_smile:

With quite some effort I got it to properly calculate the number of reinforcements I get so my first move is to place them. I thought I’d ask GPT where it thought I should place my troops and while it’s intent is good I feel like its spatial awareness is off:

You are playing a 2 player game of risk with a Human. Here is your memory:

memory:
  players: [
    {name: 'Human', color: 'red', armies: 0, cards: ['infantry', 'artillery']},
    {name: 'AI', color: 'blue', armies: 0, cards: ['cavalry', 'wild']}
  ]
  territories: [
    {name: 'Alaska', continent: 'North America', adjacent: ['Alberta', 'Northwest Territory', 'Kamchatka'], owner: players[0], armies: 3},
    {name: 'Alberta', continent: 'North America', adjacent: ['Alaska', 'Northwest Territory', 'Ontario', 'Western United States'], owner: players[0], armies: 4},
    {name: 'Central America', continent: 'North America', adjacent: ['Western United States', 'Eastern United States', 'Venezuela'], owner: players[0], armies: 2},
    {name: 'Eastern United States', continent: 'North America', adjacent: ['Central America', 'Western United States', 'Ontario', 'Quebec'], owner: players[0], armies: 4},
    {name: 'Greenland', continent: 'North America', adjacent: ['Northwest Territory', 'Ontario', 'Quebec', 'Iceland'], owner: players[0], armies: 2},
    {name: 'Northwest Territory', continent: 'North America', adjacent: ['Alaska', 'Alberta', 'Ontario', 'Greenland'], owner: players[0], armies: 3},
    {name: 'Ontario', continent: 'North America', adjacent: ['Alberta', 'Northwest Territory', 'Greenland', 'Quebec', 'Eastern United States', 'Western United States'], owner: players[0], armies: 4},
    {name: 'Quebec', continent: 'North America', adjacent: ['Ontario', 'Greenland', 'Eastern United States'], owner: players[0], armies: 3},
    {name: 'Western United States', continent: 'North America', adjacent: ['Alberta', 'Ontario', 'Eastern United States', 'Central America'], owner: players[0], armies: 4},
    {name: 'Argentina', continent: 'South America', adjacent: ['Brazil', 'Peru'], owner: players[1], armies: 2},
    {name: 'Brazil', continent: 'South America', adjacent: ['Venezuela', 'Peru', 'Argentina', 'North Africa'], owner: players[1], armies: 2},
    {name: 'Peru', continent: 'South America', adjacent: ['Venezuela', 'Brazil', 'Argentina'], owner: players[1], armies: 2},
    {name: 'Venezuela', continent: 'South America', adjacent: ['Central America', 'Brazil', 'Peru'], owner: players[1], armies: 2},
    {name: 'Great Britain', continent: 'Europe', adjacent: ['Iceland', 'Scandinavia', 'Northern Europe', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Iceland', continent: 'Europe', adjacent: ['Greenland', 'Great Britain', 'Scandinavia'], owner: players[1], armies: 2},
    {name: 'Northern Europe', continent: 'Europe', adjacent: ['Great Britain', 'Scandinavia', 'Ukraine', 'Southern Europe', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Scandinavia', continent: 'Europe', adjacent: ['Iceland', 'Great Britain', 'Northern Europe', 'Ukraine'], owner: players[1], armies: 3},
    {name: 'Southern Europe', continent: 'Europe', adjacent: ['Northern Europe', 'Ukraine', 'Middle East', 'Egypt', 'North Africa', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Ukraine', continent: 'Europe', adjacent: ['Scandinavia', 'Northern Europe', 'Southern Europe', 'Middle East', 'Afghanistan', 'Ural'], owner: players[1], armies: 4},
    {name: 'Western Europe', continent: 'Europe', adjacent: ['Great Britain', 'Northern Europe', 'Southern Europe', 'North Africa'], owner: players[1], armies: 3},
    {name: 'Congo', continent: 'Africa', adjacent: ['North Africa', 'East Africa', 'South Africa'], owner: players[0], armies: 2},
    {name: 'East Africa', continent: 'Africa', adjacent: ['Egypt', 'Middle East', 'Madagascar', 'South Africa', 'Congo', 'North Africa'], owner: players[0], armies: 2},
    {name: 'Egypt', continent: 'Africa', adjacent: ['North Africa', 'East Africa', 'Middle East', 'Southern Europe'], owner: players[0], armies: 2},
    {name: 'Madagascar', continent: 'Africa', adjacent: ['East Africa', 'South Africa'], owner: players[0], armies: 1},
    {name: 'North Africa', continent: 'Africa', adjacent: ['Brazil', 'Western Europe', 'Southern Europe', 'Egypt', 'East Africa', 'Congo'], owner: players[0], armies: 1},
    {name: 'South Africa', continent: 'Africa', adjacent: ['Congo', 'East Africa', 'Madagascar'], owner: players[0], armies: 2},
    {name: 'Afghanistan', continent: 'Asia', adjacent: ['Ukraine', 'Ural', 'China', 'India', 'Middle East'], owner: players[1], armies: 3},
    {name: 'China', continent: 'Asia', adjacent: ['Ural', 'Siberia', 'Mongolia', 'Irkutsk', 'Kamchatka', 'Japan', 'India', 'Afghanistan'], owner: players[1], armies: 4},
    {name: 'India', continent: 'Asia', adjacent: ['Middle East', 'Afghanistan', 'China', 'Siam'], owner: players[1], armies: 3},
    {name: 'Irkutsk', continent: 'Asia', adjacent: ['Siberia', 'Yakutsk', 'Kamchatka', 'Mongolia'], owner: players[1], armies: 3},
    {name: 'Japan', continent: 'Asia', adjacent: ['Mongolia', 'Kamchatka', 'China'], owner: players[1], armies: 2},
    {name: 'Kamchatka', continent: 'Asia', adjacent: ['Alaska', 'Yakutsk', 'Irkutsk', 'Mongolia', 'Japan', 'China'], owner: players[1], armies: 3},
    {name: 'Middle East', continent: 'Asia', adjacent: ['Southern Europe', 'Ukraine', 'Afghanistan', 'India', 'Egypt', 'East Africa'], owner: players[1], armies: 3},
    {name: 'Mongolia', continent: 'Asia', adjacent: ['China', 'Siberia', 'Irkutsk', 'Kamchatka', 'Japan'], owner: players[1], armies: 3},
    {name: 'Siam', continent: 'Asia', adjacent: ['India', 'China', 'Indonesia'], owner: players[1], armies: 2},
    {name: 'Siberia', continent: 'Asia', adjacent: ['Ural', 'China', 'Mongolia', 'Irkutsk', 'Yakutsk'], owner: players[1], armies: 3},
    {name: 'Ural', continent: 'Asia', adjacent: ['Ukraine', 'Afghanistan', 'China', 'Siberia'], owner: players[1], armies: 3},
    {name: 'Yakutsk', continent: 'Asia', adjacent: ['Siberia', 'Irkutsk', 'Kamchatka'], owner: players[1], armies: 3},
    {name: 'Eastern Australia', continent: 'Australia', adjacent: ['New Guinea', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'Indonesia', continent: 'Australia', adjacent: ['Siam', 'New Guinea', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'New Guinea', continent: 'Australia', adjacent: ['Indonesia', 'Eastern Australia', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'Western Australia', continent: 'Australia', adjacent: ['Indonesia', 'New Guinea', 'Eastern Australia'], owner: players[0], armies: 2}
  ]
  continents: [
    {name: 'North America', bonus: 5, territories: ['Alaska', 'Alberta', 'Central America', 'Eastern United States', 'Greenland', 'Northwest Territory', 'Ontario', 'Quebec', 'Western United States']},
    {name: 'South America', bonus: 2, territories: ['Argentina', 'Brazil', 'Peru', 'Venezuela']},
    {name: 'Europe', bonus: 5, territories: ['Great Britain', 'Iceland', 'Northern Europe', 'Scandinavia', 'Southern Europe', 'Ukraine', 'Western Europe']},
    {name: 'Africa', bonus: 3, territories: ['Congo', 'East Africa', 'Egypt', 'Madagascar', 'North Africa', 'South Africa']},
    {name: 'Asia', bonus: 7, territories: ['Afghanistan', 'China', 'India', 'Irkutsk', 'Japan', 'Kamchatka', 'Middle East', 'Mongolia', 'Siam', 'Siberia', 'Ural', 'Yakutsk']},
    {name: 'Australia', bonus: 2, territories: ['Eastern Australia', 'Indonesia', 'New Guinea', 'Western Australia']}
  ]
  phase: 'reinforce'
  current_player: players[0]
  reinforcements: 16
  source: null
  destination: null
  attacker_dice: 0
  defender_dice: 0
  dice_outcome: []
  armies_to_move: 0
  trade_in_value: 4
  winner: null

What's the best place for me to place my 16 armies?

There is no definitive answer to the best place to place the 16 armies, as different strategies may have different advantages and disadvantages. However, one possible way to approach the problem is to consider the following factors:

- The value of holding continents and preventing the opponent from holding continents, as they provide bonus armies each turn.
- The vulnerability of the territories to attack, especially from multiple directions or from large enemy forces.
- The potential for expansion and conquest, especially if the opponent has weak or isolated territories that can be easily captured.
- The balance between offense and defense, as placing too many armies on one front may leave another exposed or vice versa.

Based on these factors, one possible placement of the 16 armies is:

- 4 armies on Central America, to secure the only border with South America and threaten to invade the opponent's continent.
- 4 armies on Greenland, to secure the only border with Europe and threaten to invade the opponent's continent.
- 4 armies on Egypt, to secure the only border with the Middle East and threaten to invade the opponent's continent.
- 2 armies on Eastern Australia, to reinforce the defense of Australia and prepare to attack New Guinea or Indonesia.
- 2 armies on Congo, to reinforce the defense of Africa and prepare to attack North Africa or East Africa.

This placement would aim to achieve the following goals:

- Maintain the control of North America and Australia, which provide 7 bonus armies each turn, and deny the opponent any bonus armies from South America, Europe, or Africa.
- Create pressure on the opponent's continents by having multiple points of attack and forcing them to defend multiple borders.
- Reduce the risk of losing any territories by having at least 4 armies on each border territory and no territory adjacent to more than one enemy territory.
- Keep some options open for future expansion and conquest, depending on the opponent's moves and the cards drawn.

On the surface I’d say that Eastern Australia and Congo are complete misses… But anyone that has played Risk before knows that both of those locations are key strongholds so lets not rush to judgment… I’m going to let it play those moves and lets see how things play out. The North America suggestions are spot on…

I asked it to update its memory with those deployment locations and it did but I like how it couldn’t help but pontificate on its memory changes :slight_smile: Look at the territory changes and notice how it adds a # added n armies after each change :slight_smile:

Update your memory with those deployment locations

Possible update:

memory:
  players: [
    {name: 'Human', color: 'red', armies: 0, cards: ['infantry', 'artillery']},
    {name: 'AI', color: 'blue', armies: 0, cards: ['cavalry', 'wild']}
  ]
  territories: [
    {name: 'Alaska', continent: 'North America', adjacent: ['Alberta', 'Northwest Territory', 'Kamchatka'], owner: players[0], armies: 3},
    {name: 'Alberta', continent: 'North America', adjacent: ['Alaska', 'Northwest Territory', 'Ontario', 'Western United States'], owner: players[0], armies: 4},
    {name: 'Central America', continent: 'North America', adjacent: ['Western United States', 'Eastern United States', 'Venezuela'], owner: players[0], armies: 6}, # added 4 armies
    {name: 'Eastern United States', continent: 'North America', adjacent: ['Central America', 'Western United States', 'Ontario', 'Quebec'], owner: players[0], armies: 4},
    {name: 'Greenland', continent: 'North America', adjacent: ['Northwest Territory', 'Ontario', 'Quebec', 'Iceland'], owner: players[0], armies: 6}, # added 4 armies
    {name: 'Northwest Territory', continent: 'North America', adjacent: ['Alaska', 'Alberta', 'Ontario', 'Greenland'], owner: players[0], armies: 3},
    {name: 'Ontario', continent: 'North America', adjacent: ['Alberta', 'Northwest Territory', 'Greenland', 'Quebec', 'Eastern United States', 'Western United States'], owner: players[0], armies: 4},
    {name: 'Quebec', continent: 'North America', adjacent: ['Ontario', 'Greenland', 'Eastern United States'], owner: players[0], armies: 3},
    {name: 'Western United States', continent: 'North America', adjacent: ['Alberta', 'Ontario', 'Eastern United States', 'Central America'], owner: players[0], armies: 4},
    {name: 'Argentina', continent: 'South America', adjacent: ['Brazil', 'Peru'], owner: players[1], armies: 2},
    {name: 'Brazil', continent: 'South America', adjacent: ['Venezuela', 'Peru', 'Argentina', 'North Africa'], owner: players[1], armies: 2},
    {name: 'Peru', continent: 'South America', adjacent: ['Venezuela', 'Brazil', 'Argentina'], owner: players[1], armies: 2},
    {name: 'Venezuela', continent: 'South America', adjacent: ['Central America', 'Brazil', 'Peru'], owner: players[1], armies: 2},
    {name: 'Great Britain', continent: 'Europe', adjacent: ['Iceland', 'Scandinavia', 'Northern Europe', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Iceland', continent: 'Europe', adjacent: ['Greenland', 'Great Britain', 'Scandinavia'], owner: players[1], armies: 2},
    {name: 'Northern Europe', continent: 'Europe', adjacent: ['Great Britain', 'Scandinavia', 'Ukraine', 'Southern Europe', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Scandinavia', continent: 'Europe', adjacent: ['Iceland', 'Great Britain', 'Northern Europe', 'Ukraine'], owner: players[1], armies: 3},
    {name: 'Southern Europe', continent: 'Europe', adjacent: ['Northern Europe', 'Ukraine', 'Middle East', 'Egypt', 'North Africa', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Ukraine', continent: 'Europe', adjacent: ['Scandinavia', 'Northern Europe', 'Southern Europe', 'Middle East', 'Afghanistan', 'Ural'], owner: players[1], armies: 4},
    {name: 'Western Europe', continent: 'Europe', adjacent: ['Great Britain', 'Northern Europe', 'Southern Europe', 'North Africa'], owner: players[1], armies: 3},
    {name: 'Congo', continent: 'Africa', adjacent: ['North Africa', 'East Africa', 'South Africa'], owner: players[0], armies: 4}, # added 2 armies
    {name: 'East Africa', continent: 'Africa', adjacent: ['Egypt', 'Middle East', 'Madagascar', 'South Africa', 'Congo', 'North Africa'], owner: players[0], armies: 2},
    {name: 'Egypt', continent: 'Africa', adjacent: ['North Africa', 'East Africa', 'Middle East', 'Southern Europe'], owner: players[0], armies: 6}, # added 4 armies
    {name: 'Madagascar', continent: 'Africa', adjacent: ['East Africa', 'South Africa'], owner: players[0], armies: 1},
    {name: 'North Africa', continent: 'Africa', adjacent: ['Brazil', 'Western Europe', 'Southern Europe', 'Egypt', 'East Africa', 'Congo'], owner: players[0], armies: 1},
    {name: 'South Africa', continent: 'Africa', adjacent: ['Congo', 'East Africa', 'Madagascar'], owner: players[0], armies: 2},
    {name: 'Afghanistan', continent: 'Asia', adjacent: ['Ukraine', 'Ural', 'China', 'India', 'Middle East'], owner: players[1], armies: 3},
    {name: 'China', continent: 'Asia', adjacent: ['Ural', 'Siberia', 'Mongolia', 'Irkutsk', 'Kamchatka', 'Japan', 'India', 'Afghanistan'], owner: players[1], armies: 4},
    {name: 'India', continent: 'Asia', adjacent: ['Middle East', 'Afghanistan', 'China', 'Siam'], owner: players[1], armies: 3},
    {name: 'Irkutsk', continent: 'Asia', adjacent: ['Siberia', 'Yakutsk', 'Kamchatka', 'Mongolia'], owner: players[1], armies: 3},
    {name: 'Japan', continent: 'Asia', adjacent: ['Mongolia', 'Kamchatka', 'China'], owner: players[1], armies: 2},
    {name: 'Kamchatka', continent: 'Asia', adjacent: ['Alaska', 'Yakutsk', 'Irkutsk', 'Mongolia', 'Japan', 'China'], owner: players[1], armies: 3},
    {name: 'Middle East', continent: 'Asia', adjacent: ['Southern Europe', 'Ukraine', 'Afghanistan', 'India', 'Egypt', 'East Africa'], owner: players[1], armies: 3},
    {name: 'Mongolia', continent: 'Asia', adjacent: ['China', 'Siberia', 'Irkutsk', 'Kamchatka', 'Japan'], owner: players[1], armies: 3},
    {name: 'Siam', continent: 'Asia', adjacent: ['India', 'China', 'Indonesia'], owner: players[1], armies: 2},
    {name: 'Siberia', continent: 'Asia', adjacent: ['Ural', 'China', 'Mongolia', 'Irkutsk', 'Yakutsk'], owner: players[1], armies: 3},
    {name: 'Ural', continent: 'Asia', adjacent: ['Ukraine', 'Afghanistan', 'China', 'Siberia'], owner: players[1], armies: 3},
    {name: 'Yakutsk', continent: 'Asia', adjacent: ['Siberia', 'Irkutsk', 'Kamchatka'], owner: players[1], armies: 3},
    {name: 'Eastern Australia', continent: 'Australia', adjacent: ['New Guinea', 'Western Australia'], owner: players[0], armies: 4}, # added 2 armies
    {name: 'Indonesia', continent: 'Australia', adjacent: ['Siam', 'New Guinea', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'New Guinea', continent: 'Australia', adjacent: ['Indonesia', 'Eastern Australia', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'Western Australia', continent: 'Australia', adjacent: ['Indonesia', 'New Guinea', 'Eastern Australia'], owner: players[0], armies: 2}
  ]
  continents: [
    {name: 'North America', bonus: 5, territories: ['Alaska', 'Alberta', 'Central America', 'Eastern United States', 'Greenland', 'Northwest Territory', 'Ontario', 'Quebec', 'Western United States']},
    {name: 'South America', bonus: 2, territories: ['Argentina', 'Brazil', 'Peru', 'Venezuela']},
    {name: 'Europe', bonus: 5, territories: ['Great Britain', 'Iceland', 'Northern Europe', 'Scandinavia', 'Southern Europe', 'Ukraine', 'Western Europe']},
    {name: 'Africa', bonus: 3, territories: ['Congo', 'East Africa', 'Egypt', 'Madagascar', 'North Africa', 'South Africa']},
    {name: 'Asia', bonus: 7, territories: ['Afghanistan', 'China', 'India', 'Irkutsk', 'Japan', 'Kamchatka', 'Middle East', 'Mongolia', 'Siam', 'Siberia', 'Ural', 'Yakutsk']},
    {name: 'Australia', bonus: 2, territories: ['Eastern Australia', 'Indonesia', 'New Guinea', 'Western Australia']}
  ]
  phase: 'reinforce'
  current_player: players[0]
  reinforcements: 0 # used up all 16 armies
  source: null
  destination: null
  attacker_dice: 0
  defender_dice: 0
  dice_outcome: []
  armies_to_move: 0
  trade_in_value: 4
  winner: null

Also interesting that it knows I’ve placed all my reinforcements… We will press on that in future turns.

Ok I attacked from Central America to Venezuela… The model is horrible at math obviously. It said I lost one of my rolls but what it’s not taking into account is that it was 3 vs 2. Let me see if I can fix that

It’s also making completely ungrounded projections for how many troops the AI will get on its turn but we’ll address that later as well.

Struggling a bit to get it to better manage attacks but working on it… I do like how it expanded my one rule into what 14 rules? It’s then good at following them… working to better understand this behavior

steps:
- ask the player if they would like to attack or if they wish to reinforce?

what are the steps you should execute?

Possible steps are:

- Check if the player has any valid attack options, i.e. if they own any territory that is adjacent to an enemy territory and has more than one army on it. If not, skip to the last step.
- If the player has valid attack options, display them on the map or in a list, and ask the player to select one as the source of their attack, or to enter 'reinforce' if they wish to end their attack phase and move to the reinforcement phase. If the player enters an invalid input, ask them to try again.
- If the player selects a valid source, display the adjacent enemy territories that can be attacked from that source, and ask the player to select one as the destination of their attack, or to enter 'back' if they wish to change their source. If the player enters an invalid input, ask them to try again.
- If the player selects a valid destination, display the number of armies on both the source and the destination, and ask the player to select how many dice they want to roll for the attack, up to a maximum of three or the number of armies on the source minus one, whichever is lower. If the player enters an invalid input, ask them to try again.
- If the player selects a valid number of dice, roll the dice for the attacker and the defender, and compare the highest dice of each side. The defender loses one army for each die that is lower or equal to the attacker's die, and the attacker loses one army for each die that is higher than the defender's die. Display the dice outcome and the updated number of armies on both the source and the destination.
- If the defender loses all their armies on the destination, the attacker has conquered the territory and must move at least as many armies as the number of dice they rolled for the attack from the source to the destination. Ask the player to select how many armies they want to move, up to the number of armies on the source minus one. If the player enters an invalid input, ask them to try again.
- If the attacker loses all their armies on the source, the attack is over and the player cannot attack from that territory anymore. Ask the player to select a new source or to enter 'reinforce' if they wish to end their attack phase and move to the reinforcement phase.
- If neither the attacker nor the defender loses all their armies, the player can choose to continue the attack with the same source and destination, or to select a new source or destination, or to enter 'reinforce' if they wish to end their attack phase and move to the reinforcement phase. Repeat steps 4 to 7 until the player chooses to end their attack phase or has no more valid attack options.
- If the player chooses to end their attack phase or has no more valid attack options, check if they have conquered at least one territory during their turn. If so, draw a card from the deck and add it to their hand. If the player has more than five cards in their hand, they must trade in a set of three cards for reinforcements before moving to the reinforcement phase. A set can be either three cards of the same type (infantry, cavalry, or artillery), or one of each type, or a wild card and any two other cards. The trade in value starts at 4 and increases by 2 for each subsequent trade in by any player. Display the player's cards and the trade in value, and ask the player to select which cards they want to trade in, or to enter 'skip' if they do not want to trade in any cards. If the player enters an invalid input, ask them to try again.
- If the player trades in a set of cards, add the trade in value to their reinforcements, and remove the cards from their hand and the deck. Display the updated number of reinforcements and cards, and ask the player if they want to trade in another set of cards, or to enter 'skip' if they are done trading in cards. Repeat this step until the player is done trading in cards or has no more sets to trade in.
- If the player is done trading in cards or has no sets to trade in, move to the reinforcement phase. Display the number of reinforcements the player has, and ask the player to select which territory they want to reinforce, or to enter 'end' if they are done reinforcing. The player can only reinforce territories that they own and that are connected by a chain of their own territories. If the player enters an invalid input, ask them to try again.
- If the player selects a valid territory to reinforce, ask the player to select how many reinforcements they want to place on that territory, up to the number of reinforcements they have. If the player enters an invalid input, ask them to try again.
- If the player selects a valid number of reinforcements, subtract that number from their reinforcements, and add that number to the armies on the selected territory. Display the updated number of reinforcements and armies, and ask the player to select another territory to reinforce, or to enter 'end' if they are done reinforcing. Repeat steps 11 and 12 until the player is done reinforcing or has no more reinforcements.
- If the player is done reinforcing or has no more reinforcements, end their turn and check if they have won the game by owning all the territories on the map. If so, declare them the winner and end the game. If not, switch to the next player and start their turn.

human: attack

Possible response:

- Display the valid attack options for the player, such as:

  - Alaska (3 armies) can attack Kamchatka (3 armies)
  - Central America (6 armies) can attack Venezuela (2 armies)
  - Egypt (6 armies) can attack Southern Europe (3 armies) or Middle East (3 armies)
  - Eastern Australia (4 armies) can attack New Guinea (2 armies)

- Ask the player to select one as the source of their attack, or to enter 'reinforce' if they wish to end their attack phase and move to the reinforcement phase, such as:

  - Which territory do you want to attack from, or enter 'reinforce' to end your attack phase?

ideas welcome…

I sort of assumed this is why it expanded the set of steps but good to get confirmation:

Also worth noting that even before I asked it to give a dump of the steps it thought there were, it was obviously running a lot more steps then what I asked it to do. I’m just trying to understand what it thinks its next set of steps are and why?

Ok so I got it end… Turns out you just need to add an end step :slight_smile:

You are playing a 2 player game of risk with a Human. Here is your memory:

memory:
  players: [
    {name: 'Human', color: 'red', armies: 0, cards: ['infantry', 'artillery']},
    {name: 'AI', color: 'blue', armies: 0, cards: ['cavalry', 'wild']}
  ]
  territories: [
    {name: 'Alaska', continent: 'North America', adjacent: ['Alberta', 'Northwest Territory', 'Kamchatka'], owner: players[0], armies: 3},
    {name: 'Alberta', continent: 'North America', adjacent: ['Alaska', 'Northwest Territory', 'Ontario', 'Western United States'], owner: players[0], armies: 4},
    {name: 'Central America', continent: 'North America', adjacent: ['Western United States', 'Eastern United States', 'Venezuela'], owner: players[0], armies: 6}, # added 4 armies
    {name: 'Eastern United States', continent: 'North America', adjacent: ['Central America', 'Western United States', 'Ontario', 'Quebec'], owner: players[0], armies: 4},
    {name: 'Greenland', continent: 'North America', adjacent: ['Northwest Territory', 'Ontario', 'Quebec', 'Iceland'], owner: players[0], armies: 6}, # added 4 armies
    {name: 'Northwest Territory', continent: 'North America', adjacent: ['Alaska', 'Alberta', 'Ontario', 'Greenland'], owner: players[0], armies: 3},
    {name: 'Ontario', continent: 'North America', adjacent: ['Alberta', 'Northwest Territory', 'Greenland', 'Quebec', 'Eastern United States', 'Western United States'], owner: players[0], armies: 4},
    {name: 'Quebec', continent: 'North America', adjacent: ['Ontario', 'Greenland', 'Eastern United States'], owner: players[0], armies: 3},
    {name: 'Western United States', continent: 'North America', adjacent: ['Alberta', 'Ontario', 'Eastern United States', 'Central America'], owner: players[0], armies: 4},
    {name: 'Argentina', continent: 'South America', adjacent: ['Brazil', 'Peru'], owner: players[1], armies: 2},
    {name: 'Brazil', continent: 'South America', adjacent: ['Venezuela', 'Peru', 'Argentina', 'North Africa'], owner: players[1], armies: 2},
    {name: 'Peru', continent: 'South America', adjacent: ['Venezuela', 'Brazil', 'Argentina'], owner: players[1], armies: 2},
    {name: 'Venezuela', continent: 'South America', adjacent: ['Central America', 'Brazil', 'Peru'], owner: players[1], armies: 2},
    {name: 'Great Britain', continent: 'Europe', adjacent: ['Iceland', 'Scandinavia', 'Northern Europe', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Iceland', continent: 'Europe', adjacent: ['Greenland', 'Great Britain', 'Scandinavia'], owner: players[1], armies: 2},
    {name: 'Northern Europe', continent: 'Europe', adjacent: ['Great Britain', 'Scandinavia', 'Ukraine', 'Southern Europe', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Scandinavia', continent: 'Europe', adjacent: ['Iceland', 'Great Britain', 'Northern Europe', 'Ukraine'], owner: players[1], armies: 3},
    {name: 'Southern Europe', continent: 'Europe', adjacent: ['Northern Europe', 'Ukraine', 'Middle East', 'Egypt', 'North Africa', 'Western Europe'], owner: players[1], armies: 3},
    {name: 'Ukraine', continent: 'Europe', adjacent: ['Scandinavia', 'Northern Europe', 'Southern Europe', 'Middle East', 'Afghanistan', 'Ural'], owner: players[1], armies: 4},
    {name: 'Western Europe', continent: 'Europe', adjacent: ['Great Britain', 'Northern Europe', 'Southern Europe', 'North Africa'], owner: players[1], armies: 3},
    {name: 'Congo', continent: 'Africa', adjacent: ['North Africa', 'East Africa', 'South Africa'], owner: players[0], armies: 4}, # added 2 armies
    {name: 'East Africa', continent: 'Africa', adjacent: ['Egypt', 'Middle East', 'Madagascar', 'South Africa', 'Congo', 'North Africa'], owner: players[0], armies: 2},
    {name: 'Egypt', continent: 'Africa', adjacent: ['North Africa', 'East Africa', 'Middle East', 'Southern Europe'], owner: players[0], armies: 6}, # added 4 armies
    {name: 'Madagascar', continent: 'Africa', adjacent: ['East Africa', 'South Africa'], owner: players[0], armies: 1},
    {name: 'North Africa', continent: 'Africa', adjacent: ['Brazil', 'Western Europe', 'Southern Europe', 'Egypt', 'East Africa', 'Congo'], owner: players[0], armies: 1},
    {name: 'South Africa', continent: 'Africa', adjacent: ['Congo', 'East Africa', 'Madagascar'], owner: players[0], armies: 2},
    {name: 'Afghanistan', continent: 'Asia', adjacent: ['Ukraine', 'Ural', 'China', 'India', 'Middle East'], owner: players[1], armies: 3},
    {name: 'China', continent: 'Asia', adjacent: ['Ural', 'Siberia', 'Mongolia', 'Irkutsk', 'Kamchatka', 'Japan', 'India', 'Afghanistan'], owner: players[1], armies: 4},
    {name: 'India', continent: 'Asia', adjacent: ['Middle East', 'Afghanistan', 'China', 'Siam'], owner: players[1], armies: 3},
    {name: 'Irkutsk', continent: 'Asia', adjacent: ['Siberia', 'Yakutsk', 'Kamchatka', 'Mongolia'], owner: players[1], armies: 3},
    {name: 'Japan', continent: 'Asia', adjacent: ['Mongolia', 'Kamchatka', 'China'], owner: players[1], armies: 2},
    {name: 'Kamchatka', continent: 'Asia', adjacent: ['Alaska', 'Yakutsk', 'Irkutsk', 'Mongolia', 'Japan', 'China'], owner: players[1], armies: 3},
    {name: 'Middle East', continent: 'Asia', adjacent: ['Southern Europe', 'Ukraine', 'Afghanistan', 'India', 'Egypt', 'East Africa'], owner: players[1], armies: 3},
    {name: 'Mongolia', continent: 'Asia', adjacent: ['China', 'Siberia', 'Irkutsk', 'Kamchatka', 'Japan'], owner: players[1], armies: 3},
    {name: 'Siam', continent: 'Asia', adjacent: ['India', 'China', 'Indonesia'], owner: players[1], armies: 2},
    {name: 'Siberia', continent: 'Asia', adjacent: ['Ural', 'China', 'Mongolia', 'Irkutsk', 'Yakutsk'], owner: players[1], armies: 3},
    {name: 'Ural', continent: 'Asia', adjacent: ['Ukraine', 'Afghanistan', 'China', 'Siberia'], owner: players[1], armies: 3},
    {name: 'Yakutsk', continent: 'Asia', adjacent: ['Siberia', 'Irkutsk', 'Kamchatka'], owner: players[1], armies: 3},
    {name: 'Eastern Australia', continent: 'Australia', adjacent: ['New Guinea', 'Western Australia'], owner: players[0], armies: 4}, # added 2 armies
    {name: 'Indonesia', continent: 'Australia', adjacent: ['Siam', 'New Guinea', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'New Guinea', continent: 'Australia', adjacent: ['Indonesia', 'Eastern Australia', 'Western Australia'], owner: players[0], armies: 2},
    {name: 'Western Australia', continent: 'Australia', adjacent: ['Indonesia', 'New Guinea', 'Eastern Australia'], owner: players[0], armies: 2}
  ]
  continents: [
    {name: 'North America', bonus: 5, territories: ['Alaska', 'Alberta', 'Central America', 'Eastern United States', 'Greenland', 'Northwest Territory', 'Ontario', 'Quebec', 'Western United States']},
    {name: 'South America', bonus: 2, territories: ['Argentina', 'Brazil', 'Peru', 'Venezuela']},
    {name: 'Europe', bonus: 5, territories: ['Great Britain', 'Iceland', 'Northern Europe', 'Scandinavia', 'Southern Europe', 'Ukraine', 'Western Europe']},
    {name: 'Africa', bonus: 3, territories: ['Congo', 'East Africa', 'Egypt', 'Madagascar', 'North Africa', 'South Africa']},
    {name: 'Asia', bonus: 7, territories: ['Afghanistan', 'China', 'India', 'Irkutsk', 'Japan', 'Kamchatka', 'Middle East', 'Mongolia', 'Siam', 'Siberia', 'Ural', 'Yakutsk']},
    {name: 'Australia', bonus: 2, territories: ['Eastern Australia', 'Indonesia', 'New Guinea', 'Western Australia']}
  ]
  phase: 'attack'
  current_player: players[0]
  reinforcements: 0 # used up all 16 armies
  source: null
  destination: null
  attacker_dice: 0
  defender_dice: 0
  dice_outcome: []
  armies_to_move: 0
  trade_in_value: 4
  winner: null

steps:
- ask the player if they would like to attack or if they wish to reinforce?
- end

State each step and then explain your work for each step.

Possible steps and explanations are:

- ask the player if they would like to attack or if they wish to reinforce?
  - print a message to the player asking them to choose between attacking or reinforcing
  - wait for the player's input and validate it
  - if the player chooses to attack, set the phase to 'choose source'
  - if the player chooses to reinforce, set the phase to 'reinforce'
- end
  - check if the game is over by seeing if one player owns all the territories or if the player wishes to quit
  - if the game is over, declare the winner and exit the program
  - if the game is not over, switch the current player and start a new turn