Skip to content

Commit

Permalink
Updating TTT to be the new recipe syntax. (PolymerLabs#4034)
Browse files Browse the repository at this point in the history
* Updating TTT to be the new recipe syntax.

* Updating more schema things.

* Removing any.
  • Loading branch information
SHeimlich authored Nov 14, 2019
1 parent eb4980a commit 784965e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 101 deletions.
175 changes: 88 additions & 87 deletions particles/Tutorial/Javascript/Demo/TTTGame.arcs
Original file line number Diff line number Diff line change
Expand Up @@ -4,133 +4,134 @@ import 'TTTGameSchemas.arcs'
import 'TTTGameData.arcs'

particle Game in './source/TTTGame.js'
inout Person {name, avatar, id} playerOne
inout Person {name, avatar, id} playerTwo
inout GameState gameState
inout Move {move} playerOneMove
inout Move {move} playerTwoMove
inout [Event] events
consume root
provide gameSlot
playerOne: reads writes Person {name, avatar, id}
playerTwo: reads writes Person {name, avatar, id}
gameState: reads writes GameState
playerOneMove: reads writes Move {move}
playerTwoMove: reads writes Move {move}
events: reads writes [Event]
root: consumes
gameSlot: provides

particle TicTacToeBoard in './source/TTTBoard.js'
in GameState {board, currentPlayer} gameState
out [Event] events
consume boardSlot
gameState: reads GameState {board, currentPlayer}
events: writes [Event]
boardSlot: consumes

particle HumanPlayer in './source/TTTHumanPlayer.js'
in GameState {currentPlayer} gameState
in [Event] events
in Person {id} player
out Move {move} myMove
gameState: reads GameState {currentPlayer}
events: reads [Event]
player: reads Person {id}
myMove: writes Move {move}

particle RandomComputer in './source/TTTRandomComputer.js'
out Move {move} computerMove
in GameState {board, currentPlayer} gameState
in Person {id} player
computerMove: writes Move {move}
gameState: reads GameState {board, currentPlayer}
player: reads Person {id}

recipe GameDemoRecipe
create #volatile #humanMove as playerOneMove
create #volatile #computerMove as playerTwoMove
create #volatile as gameState
use ComputerStore as playerTwo
use HumanStore as playerOne
playerOneMove: create #humanMove
playerTwoMove: create #computerMove
playerOne: use HumanStore
playerTwo: use ComputerStore
gameState: create

Game
consume root
provide gameSlot as board
gameState = gameState
playerOne = playerOne
playerTwo = playerTwo
playerOneMove = playerOneMove
playerTwoMove = playerTwoMove
events = events
root: consumes
gameSlot: provides board
gameState: reads writes gameState
playerOne: reads writes playerOne
playerTwo: reads writes playerTwo
playerOneMove: reads writes playerOneMove
playerTwoMove: reads writes playerTwoMove
events: reads writes events

TicTacToeBoard
gameState = gameState
events = events
consume boardSlot as board
gameState: reads gameState
events: writes events
boardSlot: consumes board

HumanPlayer
gameState = gameState
events <- events
myMove -> playerOneMove
player <- playerOne
gameState: reads gameState
events: reads events
myMove: writes playerOneMove
player: reads playerOne

RandomComputer
computerMove = playerTwoMove
player = playerTwo
gameState = gameState
computerMove: writes playerTwoMove
player: reads playerTwo
gameState: reads gameState

description `Javascript Tutorial One Player TicTacToe Demo`

recipe GamePlayersDemoRecipe
create #volatile #PlayerOne as playerOneMove
create #volatile #PlayerTwo as playerTwoMove
create #volatile as gameState
use HumanOneStore as playerOne
use HumanTwoStore as playerTwo
playerOneMove: create #playerOne
playerTwoMove: create #playerTwo
gameState: create
playerOne: use HumanOneStore
playerTwo: use HumanTwoStore

Game
consume root
provide gameSlot as board
gameState = gameState
playerOne = playerOne
playerTwo = playerTwo
playerOneMove = playerOneMove
playerTwoMove = playerTwoMove
events = events
root: consumes
gameSlot: provides board
gameState: reads writes gameState
playerOne: reads writes playerOne
playerTwo: reads writes playerTwo
playerOneMove: reads writes playerOneMove
playerTwoMove: reads writes playerTwoMove
events: reads writes events

TicTacToeBoard
gameState = gameState
events = events
consume boardSlot as board
gameState: reads gameState
events: writes events
boardSlot: consumes board

HumanPlayer
gameState = gameState
events <- events
myMove -> playerOneMove
player <- playerOne
gameState: reads gameState
events: reads events
myMove: writes playerOneMove
player: reads playerOne

HumanPlayer
gameState = gameState
events <- events
myMove -> playerTwoMove
player <- playerTwo
gameState: reads gameState
events: reads events
myMove: writes playerTwoMove
player: reads playerTwo

description `Javascript Tutorial Two Players TicTacToe Demo`

recipe GameComputersDemoRecipe
create #volatile #computerOne as playerOneMove
create #volatile #computerTwo as playerTwoMove
create #volatile as gameState
use ComputerOneStore as playerOne
use ComputerTwoStore as playerTwo
playerOneMove: create #playerOne
playerTwoMove: create #playerTwo
gameState: create
playerOne: use ComputerOneStore
playerTwo: use ComputerTwoStore


Game
consume root
provide gameSlot as board
gameState = gameState
playerOne = playerOne
playerTwo = playerTwo
playerOneMove = playerOneMove
playerTwoMove = playerTwoMove
events = events
root: consumes
gameSlot: provides board
gameState: reads writes gameState
playerOne: reads writes playerOne
playerTwo: reads writes playerTwo
playerOneMove: reads playerOneMove
playerTwoMove: reads playerTwoMove
events: reads writes events

TicTacToeBoard
gameState = gameState
events = events
consume boardSlot as board
gameState: reads gameState
events: writes events
boardSlot: consumes board

RandomComputer
computerMove = playerOneMove
player = playerOne
gameState = gameState
computerMove: writes playerOneMove
player: reads playerOne
gameState: reads gameState

RandomComputer
computerMove = playerTwoMove
player = playerTwo
gameState = gameState
computerMove: writes playerTwoMove
player: reads playerTwo
gameState: reads gameState

description `Javascript Tutorial Zero Players TicTacToe Demo`

28 changes: 14 additions & 14 deletions particles/Tutorial/Javascript/Demo/TTTGameSchemas.arcs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
schema Person
Text name
Text avatar
Number id

schema GameState
Boolean gameOver
Number winnerId
Text board
Number currentPlayer
Number lastMove
gameOver: Boolean
winnerId: Number
board: Text
currentPlayer: Number
lastMove: Number

schema Event
Text type
Number move
Number time
type: Text
move: Number
time: Number

schema Move
Number move
move: Number

schema Person
name: Text
avatar: Text
id: Number

0 comments on commit 784965e

Please sign in to comment.