Skip to content

Instantly share code, notes, and snippets.

@nzifnab
Forked from anonymous/gist:1058978
Created July 1, 2011 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzifnab/1059086 to your computer and use it in GitHub Desktop.
Save nzifnab/1059086 to your computer and use it in GitHub Desktop.
start
declarations
arrFull_Deck [2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14]
arrP1_hand [ ]
arrP2_hand [ ]
arrTable [ ]
num Full_DeckCardCount = 52
num Table = 0
num P1_CardValue
num P2_CardValue
num P1_CardCount = 26
num P2_CardCount = 26
num ran_num
while Full_DeckCardCount ! = 0
distributing cards()
endwhile
while P1_CardCount, P2_CardCount !=0
Battle()
endwhile
if P1_CardCount = 0 then
output “Player 2 is the winner!”
else P2_CardCount = 0 then
output “player 1 is the winner!”
endif
stop
<Battle>
// I think you put the variables on the wrong side.
// The variable being set should be on the left side, but right now
// You're over-riding the players first card with whatever value was leftover
// in P1_CardValue. switch 'em!
1st value in arrP1_hand [ ] = P1_CardValue
1st value in arrP2_hand [ ] = P2_cardValue
// In many languages this line would have no effect because you are not actually setting or modifying
// a variable. (IE there is no 'left' or 'right' of an equals sign)
// However this is pseudocode so I understand what the line's intention is, it may be difficult to parse if the line read
// something like this: P1_CardCount - CARDS_PER_DRAWING
// Which variable are you attempting to reset to this new value? (Assuming CARDS_PER_DRAWING is a variable set to '1')
// Editing a variable inline is oftentimes done like this: P1_CardCount -= 1, or P1_CardCount += 1, where the
// operator occurs before the '=' sign, and indicates you are adding or subtracting that much from the variable itself.
// Therefore in the previous case it would read: P1_CardCount -= CARDS_PER_DRAWING
// Alternatively, and this works in most every language, you could do this: P1_CardCount = P1_CardCount - 1,
// but that's more verbose and I'd probably stick with the '-=' syntax.
P1_CardCount – 1
P2_CardCount – 1
Table + 2
copy P1_CardValue to arrTable [ ], Delete P1_cardValue from arrP1_hand [ ]
copy P2_CardValue to arrTable [ ], delete P2_cardValue from arr P2_hand [ ]
if P1_CardValue > P2_CardValue then
copy all values in arrTable [ ] to arrP1_hand [ ], delete all values in arrTable [ ]
// What if there were more than 2 cards on the table? (IE. from WAR)
// This should be P1_CardCount += Table because they are picking up all cards from the table array, and
// the Table variable stores that count.
P1_CardCount + 2
// Again if there's more than 2 cards this will fail, it should just reset the value: Table = 0
Table – 2
//The battle has ended, we shouldn't do battle again. Drop this line and let execution return back to
// Wherever we were called from
Battle()
// These should be elseif statements, and I think you should not be calling Battle() here,
// let the loop from main take care of it.
endif
if P1_CardValue < P2_CardValue then
Copy all values in arrTable [ ] to arrP2_hand [ ], delete all values In arrTable [ ]
// Same notes concerning table card count as above
P2_Cardcount + 2
Table – 2
// Again, don't call Battle here, that will happen in the main's while loop.
Battle()
endif
if P1_CardValue = P2_CardValue then
// This call *does* make sense to WAR(), because it's still part of this individual battle
// (A call to battle should go through an iteration of table-playing until the table is cleared out once,
// and then return to main to loop again)
WAR()
endif
// In some languages a return statement is optional, in some it is required. If you don't specify
// return it is implied when the code gets to the end of the module (which looks to be right here)
<WAR>
copy the first 3 values from arrP1_hand [ ] to arrTable [ ], Delete the first 3 values from arrP1_hand
copy the first 3 values from arrP2_hand [ ] to arrTable [ ], Delete the first 3 values from arrP1_hand
P1_CardCount – 3
P2_CardCount - 3
Table + 6
// We have placed 6 cards on the table, and now must do battle. Calling battle here does make sense
// Because we need a resolution to the cards that are on the table.
Battle()
<distributingCards>
rand_Num = random an index value from arrFull_Deck [ ]
P1_CardValue = arrFull_Deck [ran_num] //P1_CardValue = the value located at ran_num spot in arrFull_Deck[ ]
copy P1_CardValue to arrP1_hand [ ], delete P1_CardValue from arrFull_Deck [ ]
Full_DeckCardCount – 1
rand_num = random an index value from arrFull_Deck [ ]
P2_CardValue = arrFull_Deck [ran_num] //P1_CardValue = the value located at ran_num spot in arrFull_Deck [ ]
copy P2_CardValue to arrP2_hand [ ] , Delete P2_CardValue from arrFull_Deck [ ]
Full_DeckCardCount – 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment