Joker a Card Game Programming Language Jeffrey Eng Jonathan Tse Howard Chu Timothy SooHoo
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 LexerTree Walker Java Backend Classes DEALR Parser
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. theDeck >> 2// pop (or, deal) theDeck << myHand// push theDeck += disCards// enqueue theDeck -= 5// back-pop (dequeue) shuffle myHand[0]// indexed access
War Example game War { init { init { pack theDeck; 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 theDeck; // shuffle the deck // give half the deck pack player1Hand = (theDeck >> theDeck.size/2); pack player1Hand = (theDeck >> theDeck.size/2); // give the other ones // give the other ones pack player2Hand = (theDeck >> theDeck.size); pack player2Hand = (theDeck >> theDeck.size); }
War Example (cont) main { for(int turn=0; true; turn++) { boolean isDone = false; boolean isDone = false; card oneCard, twoCard; card oneCard, twoCard; pack prize; pack prize; int winner; int winner; while(isDone != true) { while(isDone != true) { // IF they turn out of cards, other player is winner // IF they turn out of cards, other player is winner if( player1Hand.size < 1 ) { if( player1Hand.size < 1 ) { winner = 2; break; break; } else if ( player2Hand.size < 1 ) { else if ( player2Hand.size < 1 ) { winner = 1; break; }
War Example (cont) oneCard = (player1Hand >> 1)[0]; oneCard = (player1Hand >> 1)[0]; twoCard = (player2Hand >> 1)[0]; twoCard = (player2Hand >> 1)[0]; if(oneCard lt twoCard) { if(oneCard lt twoCard) { player1Hand += oneCard; player1Hand += twoCard; player1Hand += prize; isDone = true; } else if(oneCard gt twoCard) { else if(oneCard gt twoCard) { player2Hand += oneCard; player2Hand += twoCard; player2Hand += prize; isDone = true; }
War Example (cont) else { // IF they turn out of cards, other player is winner if( player1Hand.size < 4 ) { winner = 2; break; break;} else if ( player2Hand.size < 4 ) { winner = 1; break;} // I declare war prize += oneCard; prize += twoCard; prize += player1Hand >> 3; prize += player2Hand >> 3; } }} print "The winner is "; print winner; }}
Blackjack Example game Blackjack { init { int numPlayers = 4; pack DECK; pack [ numPlayers ] playerHands; } main { boolean flipMe = true; for (int n = 1; n < = 2; n++) { foreach playerHands as hand{ hand += (DECK >> 1); hand.private = flipMe; } flipMe = false;
Blackjack Example (cont) foreach playerHands 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