Skip to content

Instantly share code, notes, and snippets.

@joshcough
Created February 4, 2016 02:23
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 joshcough/72d2c174fb693448fa55 to your computer and use it in GitHub Desktop.
Save joshcough/72d2c174fb693448fa55 to your computer and use it in GitHub Desktop.
$ stack ghci
*ghci> import Data.Aeson
*ghci> let g = unsafeNewGame [human "josh"]
*ghci> let g = unsafeNewGame [human "josh", human "nick"]
*ghci> g
Game {, [[josh rack: DOERUTO score: 0id: 0],[nick rack: ELIALIH score: 0id: 1]], ______________________________________________
|3W| | |2L| | | |3W| | | |2L| | |3W|
| |2W| | | |3L| | | |3L| | | |2W| |
| | |2W| | | |2L| |2L| | | |2W| | |
|2L| | |2W| | | |2L| | | |2W| | |2L|
| | | | |2W| | | | | |2W| | | | |
| |3L| | | |3L| | | |3L| | | |3L| |
| | |2L| | | |2L| |2L| | | |2L| | |
|3W| | |2L| | | | *| | | |2L| | |3W|
| | |2L| | | |2L| |2L| | | |2L| | |
| |3L| | | |3L| | | |3L| | | |3L| |
| | | | |2W| | | | | |2W| | | | |
|2L| | |2W| | | |2L| | | |2W| | |2L|
| | |2W| | | |2L| |2L| | | |2W| | |
| |2W| | | |3L| | | |3L| | | |2W| |
|3W| | |2L| | | |3W| | | |2L| | |3W|
----------------------------------------------
, Bag {bagTiles = [W,A,_,H,A,E,E,D,C,D,I,I,U,I,R,S,T,F,E,F,L,O,R,G,M,E,N,R,V,E,K,Y,P,I,T,Q,O,A,T,B,M,N,E,S,I,L,O,R,W,P,G,U,J,Y,D,I,G,S,A,E,N,T,S,E,I,Z,A,B,A,N,A,R,E,O,_,X,O,O,V,N,A,N,U,E,T,C]}, nr turns:0, }
*ghci> encode g
"{\"gameBoard\":[],\"gameBag\":\"WA_HAEEDCDIIUIRSTFEFLORGMENRVEKYPITQOATBMNESILORWPGUJYDIGSAENTSEIZABANAREO_XOOVNANUETC\",\"gameTurns\":[],\"gamePlayers\":[{\"playerName\":\"josh\",\"playerRack\":\"DOERUTO\",\"playerType\":\"Human\",\"playerScore\":0,\"playerId\":0},{\"playerName\":\"nick\",\"playerRack\":\"ELIALIH\",\"playerType\":\"Human\",\"playerScore\":0,\"playerId\":1}]}"
*ghci> let g' = either error id $ applyWord "ROUTED" Horizontal (7,7) [] g
*ghci> g'
Game {, [[nick rack: ELIALIH score: 0id: 1],[josh rack: OWA_HAE score: 14id: 0]], ______________________________________________
|3W| | |2L| | | |3W| | | |2L| | |3W|
| |2W| | | |3L| | | |3L| | | |2W| |
| | |2W| | | |2L| |2L| | | |2W| | |
|2L| | |2W| | | |2L| | | |2W| | |2L|
| | | | |2W| | | | | |2W| | | | |
| |3L| | | |3L| | | |3L| | | |3L| |
| | |2L| | | |2L| |2L| | | |2L| | |
|3W| | |2L| | | | R| O| U| T| E| D| |3W|
| | |2L| | | |2L| |2L| | | |2L| | |
| |3L| | | |3L| | | |3L| | | |3L| |
| | | | |2W| | | | | |2W| | | | |
|2L| | |2W| | | |2L| | | |2W| | |2L|
| | |2W| | | |2L| |2L| | | |2W| | |
| |2W| | | |3L| | | |3L| | | |2W| |
|3W| | |2L| | | |3W| | | |2L| | |3W|
----------------------------------------------
, Bag {bagTiles = [E,D,C,D,I,I,U,I,R,S,T,F,E,F,L,O,R,G,M,E,N,R,V,E,K,Y,P,I,T,Q,O,A,T,B,M,N,E,S,I,L,O,R,W,P,G,U,J,Y,D,I,G,S,A,E,N,T,S,E,I,Z,A,B,A,N,A,R,E,O,_,X,O,O,V,N,A,N,U,E,T,C]}, nr turns:1, }
*ghci> encode g'
"{\"gameBoard\":[[[7,7],\"R\"],[[8,7],\"O\"],[[9,7],\"U\"],[[10,7],\"T\"],[[11,7],\"E\"],[[12,7],\"D\"]],\"gameBag\":\"EDCDIIUIRSTFEFLORGMENRVEKYPITQOATBMNESILORWPGUJYDIGSAENTSEIZABANAREO_XOOVNANUETC\",\"gameTurns\":[{\"rackRemainder\":\"O\",\"points\":14,\"tilesPlayed\":{\"wordPutTiles\":[[[7,7],\"R\",1],[[8,7],\"O\",1],[[9,7],\"U\",1],[[10,7],\"T\",1],[[11,7],\"E\",1],[[12,7],\"D\",2]]},\"tilesTakenFromBag\":\"WA_HAE\",\"playerId\":0}],\"gamePlayers\":[{\"playerName\":\"nick\",\"playerRack\":\"ELIALIH\",\"playerType\":\"Human\",\"playerScore\":0,\"playerId\":1},{\"playerName\":\"josh\",\"playerRack\":\"OWA_HAE\",\"playerType\":\"Human\",\"playerScore\":14,\"playerId\":0}]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment