Child of PitGame

No preview image

1 collaborator

Default-person Andrew Yip (Author)

Tags

(This model has yet to be categorized with any tags)
Child of model PitGame preview imagePitGame
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.2 • Viewed 263 times • Downloaded 18 times • Run 0 times
Download the 'Child of 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
;; modified and extended by Andrew Yip 23 Oct 2017
;; for components and rules https://tametheboardgame.com/category/published-games/pit/
extensions [sound cf array]

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

breed [players player]

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

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

to setup
  ca
  set scores array:from-list [0 0 0 0 0]
  set round-counter 0
end 

to setup-round
  ct ; reset turtles
  set deck []
  set xcards1 []
  set xcards2 []
  set this-trader-g "--"
  set other-trader-g "--"
  set winner []
  set do-trade true
  create-players 5 [set cards [] set color red set label who set shape "circle" set xcor 1 set ycor 6 - 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]
  repeat 9 [set deck fput "barley" deck] ; add 5th commodity
  set deck (sentence "bull" "bear" deck) ; add bull bear cards
  ;; if increasing the number of players, add 9 cards of another commodity, like barley

  set deck shuffle deck ; no need for repeat 9 here
  deal
  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 []
    set won false
  ]
  ask n-of 2 players [
    set cards sentence cards first deck
    set deck but-first deck
  ]
  ; deal 1 extra card each to 2 random players
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 [ [commodity] ->
      if commodity = "oats"  [ask patch this-xcor this-ycor [set pcolor white]]
      if commodity = "corn"  [ask patch this-xcor this-ycor [set pcolor yellow]]
      if commodity = "wheat" [ask patch this-xcor this-ycor [set pcolor blue]]
      if commodity = "flax"  [ask patch this-xcor this-ycor [set pcolor green]]
      if commodity = "barley" [ask patch this-xcor this-ycor [set pcolor pink]]
      if commodity = "bull" [ask patch this-xcor this-ycor [set pcolor cyan]]
      if commodity = "bear" [ask patch this-xcor this-ycor [set pcolor grey]]
      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 remove "bull" trade-set
      ; remove bull from 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-report occurrences [x the-list]
  report reduce
    [ [occurrence-count next-item] -> ifelse-value (next-item = x) [occurrence-count + 1] [occurrence-count] ] (fput 0 the-list)
end 

; TODO: offer bear card first
; TODO: trade out low value cards first at a tie

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
  ; add bull corner
  ; add double bull corner
  ; penalize bear or bull losing holders
  ask players [
    if member? "bull" cards and occurrences one-of modes cards cards = 9 [
      output-show (word round-counter ": Double Bull Winner! (" item 2 cards ")")
      sound:play-note "tubular bells" 100 111 2
      set winner lput who winner
      set do-trade false
      score-winner one-of modes cards "double"
      set won true
      stop ]

    ; add bull corner
    if member? "bull" cards and occurrences one-of modes cards cards = 8 [
      output-show (word round-counter ": Bull Winner! (" item 2 cards ")")
      sound:play-note "tubular bells" 100 111 2
      set winner lput who winner
      set do-trade false
      score-winner one-of modes cards ""
      set won true
      stop ]

    if occurrences one-of modes cards cards = 9 [
      output-show (word round-counter ": Winner! (" item 1 cards ")" )
      sound:play-note "tubular bells" 100 111 2
      set winner lput who winner
      set do-trade false
      score-winner one-of modes cards ""
      set won true
      stop ]
  ]
;  output-print "end select-offer" output-print ""
end 

to score-winner [commodity mode]
  let price 0
  cf:match commodity
  cf:case [c -> c = "wheat"] [set price 100]
  cf:case [c -> c = "barley"] [set price 85]
  cf:case [c -> c = "corn"] [set price 75]
  cf:case [c -> c = "oats"] [set price 60]
  cf:else [set price 50] ; fictional price
  cf:match mode
  cf:case [m -> m = "double"] [array:set scores who 2 * price + array:item scores who]
  cf:else [array:set scores who price + array:item scores who]
end 

to penalize-loser
  ask players with [won = false] [
    if member? "bull" cards [array:set scores who array:item scores who - 20]
    if member? "bear" cards [array:set scores who array:item scores who - 20]
  ]
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]]
      if ?1 = "barley" [ask patch this-xcor this-ycor [set pcolor pink]]
      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 

to one-round
  setup-round
  while [length winner < 1] [
  analyze-position
  find-and-make-trade
  ]
  penalize-loser
  print (word round-counter ":" scores)
  set round-counter round-counter + 1
end 

;  write game-loop until score of player > 500

to one-game
  while [max (array:to-list scores) < 500] [
    one-round
  ]
  print (word "player "  position max (array:to-list scores) array:to-list scores " wins with score " max (array:to-list scores))
  stop
  ; TODO: fix behaviorSpace not stopping
end 

There is only one version of this model, created about 6 years ago by Andrew Yip.

Attached files

No files

Parent: PitGame

This model does not have any descendants.

Graph of models related to 'Child of PitGame'