Last active
May 7, 2020 21:40
-
-
Save chukinas/8c177ebcb2841cdbaef6eae6cb7973b0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hiddenClues = { | |
id: 'hiddenClues', | |
initial: 'thinking', | |
states: { | |
thinking: { | |
on: { | |
SUBMIT_CLUE: { | |
target: 'waiting', | |
cond: 'isSelfEvent', | |
} | |
}, | |
}, | |
waiting: {}, | |
}, | |
on: { | |
SUBMIT_CLUE: { | |
actions: '' | |
} | |
} | |
} | |
const clueTurnMachine = { | |
id: 'clueGiver', | |
onDone: '#game.preTurn', | |
states: { | |
hiddenClues, | |
judge_duplicates: { | |
on: {DUPS_REJECTED: 'awaiting_guess'} | |
}, | |
awaiting_guess: { | |
on: { | |
SKIP_GUESS: 'resolve_skipped_guess', | |
GUESS_SUBMITTED: 'judging_guess' | |
} | |
}, | |
judging_guess: { | |
on: {GUESS_JUDGED: 'resolve_clue_turn'} | |
}, | |
resolve_clue_turn: { | |
on: {TIMER: 'end_turn'} | |
}, | |
resolve_skipped_guess: { | |
on: {TIMER: 'end_turn'} | |
}, | |
end_turn: { | |
after: { | |
// 500: 'clue-turn-machine.awaiting_clues' | |
500: '#beginGuessTurn' | |
} | |
// type: 'final' | |
}, | |
} | |
}; | |
const guessTurnMachine = { | |
id: 'guesser', | |
initial: 'begin_turn', | |
onDone: '#game.preTurn', | |
states: { | |
begin_turn: { | |
id: 'beginGuessTurn', | |
after: {5000: 'awaiting_clues'} | |
}, | |
awaiting_clues: { | |
on: {DUPS_REJECTED: 'see_clues'} | |
}, | |
see_clues: { | |
after: {5000: 'making_guess'} | |
}, | |
making_guess: { | |
on: { | |
GUESS_SUBMITTED: 'awaiting_judgment', | |
SKIP_GUESS: 'resolve_skip' | |
} | |
}, | |
awaiting_judgment: { | |
on: { | |
GUESS_JUDGED: 'resolve_guess' | |
} | |
}, | |
resolve_guess: { | |
after: { | |
1000: 'end_turn' | |
} | |
}, | |
resolve_skip: { | |
after: { | |
1000: 'end_turn' | |
} | |
}, | |
end_turn: { | |
type: 'final' | |
} | |
} | |
} | |
const guards = { | |
isSelfEvent: ()=>true, | |
} | |
const justOneMachine = Machine({ | |
id: 'game', | |
context: { | |
selfID: 2, | |
guesserID: 1, | |
cluerIDs: [2, 3, 4, 5, 6], | |
turnNumber: 3, | |
}, | |
initial: 'preTurn', | |
states: { | |
preTurn: { | |
entry: 'updateContext' | |
}, | |
clue_turn: { | |
// on: {END_CLUE_TURN: 'guess_turn'}, | |
...clueTurnMachine | |
}, | |
guess_turn: { | |
...guessTurnMachine | |
} | |
} | |
}, | |
{ | |
guards, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment