Created
September 12, 2016 11:27
-
-
Save anonymous/39ed5d16434bdb083b3a39bb83c2c013 to your computer and use it in GitHub Desktop.
Rock-Paper-Scissor in EVE
This file contains hidden or 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
# Rock Scissor Paper | |
Based on https://rosettacode.org/wiki/Rock-paper-scissors | |
Rules are simple: | |
The winner is decided by a set of rules: | |
* Rock beats scissors | |
* Scissors beat paper | |
* Paper beats rock | |
``` | |
match | |
[#session-connect] | |
commit | |
[#win-condition winner: "rock" looser: "scissor"] | |
[#win-condition winner: "scissor" looser: "paper"] | |
[#win-condition winner: "paper" looser: "rock"] | |
[#choice kind: "rock", id: 0] | |
[#choice kind: "scissor", id: 1] | |
[#choice kind: "paper", id: 2] | |
[@app aiScore: 0, playerScore: 0] | |
``` | |
## Present the user a choice | |
``` | |
match | |
choice = [#choice kind] | |
app = [@app] | |
bind | |
[#div text: "Choose your weapon: " children: | |
[#button @choice choice text: "{{kind}}"] | |
[#div app text: "Player-Score: {{app.playerScore}}, AI-Score: {{app.aiScore}}"]] | |
``` | |
## What happens, when the user clicks on a choice? | |
``` | |
match | |
anybutton = [#button @choice] | |
[#click #direct-target element: anybutton] | |
choice = anybutton.choice | |
app = [@app] | |
bind | |
app.player := choice.kind | |
``` | |
## The AI chooses, when the user made a choice | |
``` | |
match | |
app = [@app player] | |
rnd = random[seed: 1] * 1000 | |
id = round[value: mod[value: rnd, by: 2]] | |
ai_choice = [#choice id] | |
bind | |
app.ai := ai_choice.kind | |
``` | |
## Evaluate the winning condition: | |
``` | |
match | |
app = [@app player ai playerScore aiScore] | |
(who_wins, newPlayerScore, newAiScore) = if [#win-condition winner: player, looser: ai] then ("player", playerScore + 1, aiScore) | |
else if [#win-condition winner: ai, looser: player] then ("AI", playerScore, aiScore + 1) | |
else ("Nobody, It's a draw.", playerScore, aiScore) | |
bind | |
// These two lines break the execution (no results are shown) ====== | |
// app.playerScore := newPlayerScore | |
// app.aiScore := newAiScore | |
// ================================================================= | |
[#div text: "-> {{player}} vs {{ai}} => who won? {{who_wins}}"] | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment