Joker a Card Game Programming Language Jeffrey Eng








![War Example (cont) one. Card = (player 1 Hand >> 1)[0]; two. Card = War Example (cont) one. Card = (player 1 Hand >> 1)[0]; two. Card =](https://slidetodoc.com/presentation_image/78fb5ecb883e661c515821dce8fe724a/image-9.jpg)




- Slides: 13
Joker a Card Game Programming Language Jeffrey Eng Jonathan Tse Howard Chu Timothy Soo. Hoo
Motivation Ø Ø Structure & rule-driven nature of card games Succinctly describe the rules of a card game Create a runtime card game engine Framework for creating standard games
Feature Overview Special Pack datatype and operators Ø Hierarchy declaration Ø Program structure Ø Java-like syntax Ø
Compiler Architecture *. jkr Lexer Parser Java Backend Classes DEALR Tree Walker
Pack of Cards Deck of cards is embedded in the language Ø known as the "pack" type. Ø essentially a super data structure with many list -like operations Ø Ø In general, this is a grouping of cards. Can be used for the deck, player's hands, discard piles, etc.
Pack Operators Ø Ø Ø Ø The value of these expressions is a reference to a new pack containing the removed cards or the newly combined cards. the. Deck >> the. Deck << the. Deck += the. Deck -= the. Deck@ my. Hand[0] 2 my. Hand dis. Cards 5 // // // pop (or, deal) push enqueue back-pop (dequeue) shuffle indexed access
War Example game War { init { pack the. Deck; hierarchy : { A(14), K(13), Q(12), J(11), 10(10), 9(9), 8(8), 7(7), 6(6), 5(5), 4(4), 3(3), 2(2) } by { spades(1). hearts. clubs. diamonds } into the. Deck; // shuffle the deck the. Deck@; // give half the deck pack player 1 Hand = (the. Deck >> the. Deck. size/2); // give the other ones pack player 2 Hand = (the. Deck >> the. Deck. size); }
War Example (cont) main { for(int turn=0; true; turn++) { boolean is. Done = false; card one. Card, two. Card; pack prize; int winner; while(is. Done != true) { // IF they turn out of cards, other player is winner if( player 1 Hand. size < 1 ) { winner = 2; break; } else if ( player 2 Hand. size < 1 ) { winner = 1; break; }
War Example (cont) one. Card = (player 1 Hand >> 1)[0]; two. Card = (player 2 Hand >> 1)[0]; if(one. Card lt two. Card) { player 1 Hand += one. Card; player 1 Hand += two. Card; player 1 Hand += prize; is. Done = true; } else if(one. Card gt two. Card) { player 2 Hand += one. Card; player 2 Hand += two. Card; player 2 Hand += prize; is. Done = true; }
War Example (cont) else { // IF they turn out of cards, other player is winner if( player 1 Hand. size < 4 ) { winner = 2; break; } else if ( player 2 Hand. size < 4 ) { winner = 1; break; } // I declare war prize += one. Card; prize += two. Card; prize += player 1 Hand >> 3; prize += player 2 Hand >> 3; } } } print "The winner is "; print winner; } }
Blackjack Example game Blackjack { init { int num. Players = 4; pack DECK; pack [ num. Players ] player. Hands; } main { boolean flip. Me = true; for (int n = 1; n < = 2; n++) { foreach player. Hands as hand{ hand += (DECK >> 1); hand<bottom>. private = flip. Me; } flip. Me = false;
Blackjack Example (cont) foreach player. Hands as hand { while(true) { int sum = 0; foreach hand as card { sum += card. value; } option (hand) hit (sum <= 21) {…} stand (sum <= 21) {…} bust (sum > 21) {…} } }
Lessons Learned Communication Ø Divide and conquer Ø Project schedule / milestones Ø Set realistic goals Ø Start early Ø Stay focused on the core objectives Ø













