PitGame

PitGame preview image

1 collaborator

Default-person Doug Edmunds (Author)

Tags

game simulation 

Tagged by Doug Edmunds over 6 years ago

Parent of 1 model: Child of PitGame
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0 • Viewed 336 times • Downloaded 21 times • Run 0 times
Download the 'PitGame' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

PitGame is a trading game simulation based on "Pit." Pit is a fast-paced card game for three to seven players, designed to simulate open outcry bidding for commodities. The game was developed for Parker Brothers and first sold in 1904.

Each player gets 9 cards tries to get all his cards to match, by trading from 1 to 4 to cards with other players (1 for 1, 2 for 2, etc). The cards given away have to be the same (all wheat, all corn). In the live game everyone plays at once, trading with other players until there is a winner. There are no 'turns' per se.

The simulation provides a model for competitive concurrent action by agents, and also explores the coding issues involved in maintaining changes to lists.

HOW IT WORKS

In order to simulate trading all at once, only one trade is allowed per turn, but who gets to trade is randomly selected in each turn. It is possible that player 2 gets to trade several times in a row, while player 1 doesn't get to trade at all.

In the simulation there are 4 players (0,1,2,3) and 4 commodities (wheat, corn, oats, and flax). There are 9 cards for each commodity. The players try to 'corner the market' by trading with each other to get all 9 cards of a commodity. When a player gets all the cards of a commodity, he is the winner.

HOW TO USE IT

Make sure the output window appears as a large box on the right hand side.

Click "Setup" to deal out original 9 cards held by each player.

The sequence is Analyze-Trade, Analyze-Trade, etc. You can combine these two steps with the "Analyze and Trade" button, or you can click "Play to End" for the simulation to continue until there is a winner.

Click "Analyze" for each player to analyze and report their position.

Click "Trade" to do a trade. The rule is that n order for there to be a trade, two players must offer each other the same quantity (1,2,3 or 4). The offer must be of the same commodity (i.e., 3 wheat, not 2 wheat and 1 corn). If more than two players offer the same quantity, then a random selection of two players is made. The traders cannot see the type of commodity that is being offered to them.

Click 'Analyze and Trade' to combine analyze and trade.

Click "Play to end", which repeats until there is a winner.

A bell will ring when there is a winner.

THINGS TO NOTICE

There are a lot of output boxes so you can see who is trading away what.

Look at the code to see how lists are manipulated to extract trade-sets and how exchanges are made between the players

Each 'round' only allows one trade, between two of the players. When more than two players offer the same count, they are selected randomly.

Sometimes the players will get "stuck" for several rounds, offering each other the same things (like 2 wheat for 2 wheat) so there is no change. That is part of the game, so it should not be avoided. Eventually, due to the randomization, this deadlock will break, so just click Step again until it does.

THINGS TO TRY

Does the simulation model the real game? To see how the card game runs out with real players, print out the rules, get together with 3 friends, and use some ordinary playing cards instead of buying a special deck (use the suits as 'commodities'). Get something to ding on unless you have a bell to ring.

EXTENDING THE MODEL

The original card game awarded more points depending on the commodities: Wheat 100; Barley 85; Corn 75; Rye 70; Oats 60; Hay 50; Flax 40. The model does not prioritize.

You could better understand the code if you increase the number of players to 5 and add another set of 9 cards to the deck (such as barley, rice, or soybeans). You should add a monitor for the additional player's holdings and for the additional player's offer-count.

The players are self-focused. Each player makes selections of cards to keep based on which cards he has the most of, and doesn't try to keep track of what the other players may be going for. Also the players randomly decide how many cards to trade. What would you change to make them smarter players?

The card game rules also have a version which uses two wild cards - a Bear and a Bull. The rules are online (see link below for the pdf). You could add those cards to the game to enhance it.

The card game also gives more points for trying to corner certain commodities, so there would be an incentive to go for the one that gets more points, especially in the case of a tie between cards in the player's hand. That aspect is not included in the basic simulation.

NETLOGO FEATURES

Look at the code to see how the lists are manipulated to extract trade-sets and how exchanges are made.

RELATED MODELS

None I am aware of.

CREDITS AND REFERENCES

The original game is called Pit, and was designed to be played by 3 to 7 people. The rules can be downloaded as a PDF file from http://www.hasbro.com/common/instruct/pit.pdf

More information about the history of the game at http://en.wikipedia.org/wiki/Pit_(game)

NetLogo code developed by Doug Edmunds.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; PitGame v2.2 7 Feb 2017
;; world window version 2
;; requires NetLogo 6.0 or higher
;; by Doug Edmunds
;; based on the Pit card game

extensions [sound]

globals [deck  do-trade xcards1 xcards2 winner this-trader-g other-trader-g]

breed [players player]

players-own [cards keepers trade-set offered-cards offered-count]

to output-help
  output-print "Corn - yellow, Oats - white,"
  output-print "Wheat - blue, Flax - green"
  output-print "Dice show last traders"
end 

to setup
  ca
  set deck []
  set xcards1 []
  set xcards2 []
  set this-trader-g "--"
  set other-trader-g "--"
  set winner []
  set do-trade true
  create-players 4 [set cards [] set color red set label who set shape "circle" set xcor 1 set ycor 5 - who]
  repeat 9 [set deck fput "oats" deck]
  repeat 9 [set deck fput "corn" deck]
  repeat 9 [set deck fput "wheat" deck]
  repeat 9 [set deck fput "flax" deck]

  ;; if increasing the number of players, add 9 cards of another commodity, like barley

  repeat 9 [set deck shuffle deck]
  deal
  output-help
  reset-ticks
end 

to deal
  ask players [
    repeat 9 [
      set cards sentence cards first deck
      set deck but-first deck]
    set cards sort cards
    set keepers []
    set trade-set []
  ]
end 

to analyze-position
  output-print ""
  select-keepers
  select-offer
end 

to select-keepers
  set do-trade true

  foreach sort players [ [?1] ->
   ask ?1 [
    let most-cards one-of modes cards

;; leave this here for the setup
    let card-pos 1
    let this-xcor  xcor + 2
    let this-ycor  ycor
;    show list this-xcor this-ycor

    foreach cards [ [??1] ->
      if ??1 = "oats"  [ask patch this-xcor this-ycor [set pcolor white]]
      if ??1 = "corn"  [ask patch this-xcor this-ycor [set pcolor yellow]]
      if ??1 = "wheat" [ask patch this-xcor this-ycor [set pcolor blue]]
      if ??1 = "flax"  [ask patch this-xcor this-ycor [set pcolor green]]
      set this-xcor this-xcor + 1
      ]


    set keepers []
    set trade-set[]
    foreach cards [ [??1] -> ifelse ??1 = most-cards
      [set keepers lput ??1 keepers]
      [set trade-set lput ??1 trade-set] ]
    set trade-set sort trade-set
    output-show word "I am cornering " most-cards
    output-show word "My trade-set is " trade-set
    ]
   ]
  output-print "end select-keepers" output-print ""
end 

to select-offer
  foreach sort players [ [?1] ->
      ask ?1 [
      set offered-cards []
      set offered-count 0
      ;output-show word "I am player "  who
      if length trade-set > 0
        ;;create a list with no duplicates to trade away
        ;;pick one
        ;;figure out how many player has of the choice
        ;;offer random quantity up to maximum of that one
        [let no-dupe-list remove-duplicates trade-set
          let trade-pick one-of no-dupe-list
          set offered-count length filter [ [??1] -> ??1 = trade-pick ] trade-set
          ;; reduce to a random amount > 0, less than max
          ;; output-show word "before random: " offered-count
          set offered-count (random offered-count) + 1
          output-show (word "Player " who " offers " offered-count " (" trade-pick ")" )
          repeat offered-count [set offered-cards lput trade-pick offered-cards]
        ]

      ]
    ]
  ;; if more than one winner, whoever is first to ring the bell wins
  ask players [if length trade-set = 0 [output-show (word "Winner! (" item 1 cards ")" )
          sound:play-note "tubular bells" 100 111 2
          set winner lput who winner
          set do-trade false
          stop ]]

  output-print "end select-offer" output-print ""
end 

to find-and-make-trade
  output-print ""
  ask players [
    let my-count offered-count
    ;; do-trade is global, changed to false in make-trade
    if do-trade and any? other players with [offered-count  = my-count]
    [ make-trade my-count]


    let card-pos 1
    let this-xcor  xcor + 2
    let this-ycor  ycor
;    show list this-xcor this-ycor

    foreach cards [ [?1] ->
      if ?1 = "oats"  [ask patch this-xcor this-ycor [set pcolor white]]
      if ?1 = "corn"  [ask patch this-xcor this-ycor [set pcolor yellow]]
      if ?1 = "wheat" [ask patch this-xcor this-ycor [set pcolor blue]]
      if ?1 = "flax"  [ask patch this-xcor this-ycor [set pcolor green]]
      set this-xcor this-xcor + 1
      ]

  ]

    output-print "end find-and-make-trade" output-print ""
    tick
end 


;; this is done by a player, so output-show cards is that player's cards

to make-trade [my-count]
 ;exchange same number of cards
 ;then set do-trade false
 ;this bogs down if same cards are returned
 ;output-show sentence  who  offered-cards
 output-show offered-cards
 let other-trader nobody
 let this-trader who
 ask one-of other players with [offered-count = my-count]
    [ output-show offered-cards
      set other-trader who
      ]
 exchange-cards this-trader other-trader
 set do-trade false
end 

;; this is done by the same player from inside make-trade

to exchange-cards [this-trader other-trader]
  ask players [set shape "circle"]
  ask player this-trader [
    set shape "die 1"
    foreach offered-cards [ [?1] ->
    let pull-card-index position ?1 cards
    set cards remove-item pull-card-index cards
    ]]

  ask player other-trader [
    set shape "die 2"
    foreach offered-cards [ [?1] ->
    let pull-card-index position ?1 cards
    set cards remove-item pull-card-index cards
    ]]

    set this-trader-g this-trader
    set other-trader-g other-trader

    set xcards1 ([offered-cards] of player this-trader)
    set xcards2 ([offered-cards] of player other-trader)

    ask player this-trader  [set cards sentence cards xcards2]
    ask player other-trader [set cards sentence cards xcards1]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Doug Edmunds over 3 years ago For NetLogo 6.0 Download this version
Doug Edmunds about 6 years ago Graphic display added Download this version
Doug Edmunds over 6 years ago Initial upload Download this version

Attached files

File Type Description Last updated
pit.pdf pdf Official rules of the card game over 6 years ago, by Doug Edmunds Download
PitGame.png preview Replacement for prev interface image about 6 years ago, by Doug Edmunds Download

This model does not have any ancestors.

Children:

Graph of models related to 'PitGame'