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.

Download Report

Transcript 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.

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
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 listlike 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 >>
theDeck <<
theDeck +=
theDeck -=
theDeck@
myHand[0]
2
myHand
disCards
5
//
//
//
//
//
//
pop (or, deal)
push
enqueue
back-pop (dequeue)
shuffle
indexed access
War Example
game War {
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
theDeck@;
// give half the deck
pack player1Hand = (theDeck >> theDeck.size/2);
// give the other ones
pack player2Hand = (theDeck >> theDeck.size);
}
War Example (cont)
main {
for(int turn=0; true; turn++) {
boolean isDone = false;
card oneCard, twoCard;
pack prize;
int winner;
while(isDone != true) {
// IF they turn out of cards, other player is winner
if( player1Hand.size < 1 ) {
winner = 2;
break;
}
else if ( player2Hand.size < 1 ) {
winner = 1;
break;
}
War Example (cont)
oneCard = (player1Hand >> 1)[0];
twoCard = (player2Hand >> 1)[0];
if(oneCard lt twoCard) {
player1Hand += oneCard;
player1Hand += twoCard;
player1Hand += prize;
isDone = true;
}
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;
}
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<bottom>.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
