cardigan
play

Cardigan Card Game Development Joshua Lopez (Team Leader) Muzi Gao - PowerPoint PPT Presentation

Cardigan Card Game Development Joshua Lopez (Team Leader) Muzi Gao * Miriam Melnick Introduction What is Cardigan? Here's a hint, it's not a sweater. Card game development & implementation language Built in data types which


  1. Cardigan Card Game Development Joshua Lopez (Team Leader) Muzi Gao * Miriam Melnick

  2. Introduction What is Cardigan? Here's a hint, it's not a sweater. ● Card game development & implementation language ● Built in data types which support card game elements (cards, players, etc.) ● Control structures for game play (rules, turns, winning conditions, etc.)

  3. Motivation ● Developing card games is tedious ● Materials are expensive ● Physical iteration takes time

  4. Motivation Developing in code allows ● no cost for materials ● easy modification ● fast iteration ● better development

  5. Tutorial WAR!

  6. scanner.mll Lexical Analysis converts source file to tokens ID ASSIGN LBRAC ID COMMA ID COMMA ID COMMA ID RBRAC EOL ID ASSIGN LBRAC STRING COMMA suits = |hearts, clubs, diamonds, spades| STRING COMMA STRING COMMA ranks = ["a","k", "q", "j", "10", "9", "8", "7",\ STRING COMMA STRING COMMA "6", "5", "4", "3", "2"] STRING COMMA STRING COMMA PLAY()={ STRING COMMA STRING COMMA deck = cartesian(suits, ranks) STRING COMMA STRING COMMA player = {name:"", score:0, hand:[]} STRING COMMA STRING RBRAC EOL ID LPAREN RPAREN ASSIGN LCURL ID ASSIGN ID LPAREN ID COMMA ID RPAREN EOL ID ASSIGN LCURL ID COLON STRING COMMA ID COLON INT COMMA ID COLON LBRAC RBRAC RCURL EOL ...

  7. parser.mly + ast.mli Syntactic analysis creates an abstract syntax tree ID ASSIGN LBRAC ID COMMA ID program COMMA ID COMMA ID RBRAC EOL ID ASSIGN LBRAC STRING COMMA STRING COMMA STRING COMMA STRING COMMA STRING COMMA STRING COMMA STRING COMMA = = = STRING COMMA STRING COMMA STRING COMMA STRING COMMA STRING COMMA STRING RBRAC EOL ID LPAREN RPAREN ASSIGN LCURL ID () [ ] {} ID ID | | ID ASSIGN ID LPAREN ID COMMA ID RPAREN EOL ID ASSIGN LCURL ID COLON STRING COMMA ID COLON INT COMMA ID COLON LBRAC RBRAC RCURL EOL ...

  8. cardigan.ml Compiling an AST in 3 stages ● Separator ○ Breaks off subtrees ● Semantic analysis ○ Keeps track of types in a symbol table ○ Checks each subtree to make sure types are valid ● Code generation ○ Creates Java code from templates

  9. Implementation AST Cardigan Definitions Source Scanner Parser Translator Tokens Lexical A. S. T. Semantic Syntactic Analysis Analysis Analysis Code Generation hello cardigan JVM Javac Java Bytecode Java Source Java Execution Compilation Standard Library

  10. Lessons Learned ● Newline characters are not good line delimiters ● Type inference is hard ● Ocaml is hard to debug ● It's possible to start too early ● Work with "real" code as well as tests the whole time

More recommend