Sets
Sets have a non-transitive relation, similarly to rock paper scissors. I used this property to implement the game win conditions.
def dumbRockPaperScissors(player1, player2): Rock = {"Paper"} Paper = {"Scissors"} Scissors = {"Rock"} if player1 in eval(player2): return "Player 1 wins" elif player2 in eval(player1): return "Player 2 wins" else: return "Draw"
function dumbRockPaperScissors(player1, player2) {if(player1 == "Rock" && player2 == "Paper"){return "Player 2 wins";}else if(player1 == "Rock" && player2 == "Scissors" ){return "Player 1 wins";}else if(player1 == "Scissors" && player2 == "Paper"){return "Player 1 wins";}else if(player1 == "Scissors" && player2 == "Rock"){return "Player 2 wins";}else if(player1 == "Paper" && player2 == "Scissors"){return "Player 2 wins";}else if(player1 == "Paper" && player2 == "Rock"){return "Player 1 wins";}else if(player1 == "Paper" && player2 == "Paper"){return "Draw";}else if(player1 == "Rock" && player2 == "Rock"){return "Draw";}else if(player1 == "Scissors" && player2 == "Scissors"){return "Draw";}}- def dumbRockPaperScissors(player1, player2):
- Rock = {"Paper"}
- Paper = {"Scissors"}
- Scissors = {"Rock"}
- if player1 in eval(player2):
- return "Player 1 wins"
- elif player2 in eval(player1):
- return "Player 2 wins"
- else:
- return "Draw"
import codewars_test as test from solution import dumbRockPaperScissors @test.describe("dumbRockPaperScissors") def fixed_tests(): @test.it('Basic Test Cases') def basic_test_cases(): test.assert_equals(dumbRockPaperScissors('Rock', 'Rock'),'Draw') test.assert_equals(dumbRockPaperScissors('Rock', 'Paper'),'Player 2 wins') test.assert_equals(dumbRockPaperScissors('Paper', 'Rock'),'Player 1 wins') test.assert_equals(dumbRockPaperScissors('Paper', 'Paper'),'Draw') test.assert_equals(dumbRockPaperScissors('Rock', 'Scissors'),'Player 1 wins') test.assert_equals(dumbRockPaperScissors('Paper', 'Scissors'),'Player 2 wins') test.assert_equals(dumbRockPaperScissors('Scissors', 'Rock'),'Player 2 wins') test.assert_equals(dumbRockPaperScissors('Scissors', 'Paper'),'Player 1 wins') test.assert_equals(dumbRockPaperScissors('Scissors', 'Scissors'),'Draw')
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.const chai = require("chai");const assert = chai.assert;// Uncomment the following line to disable truncating failure messages for deep equals, do:// chai.config.truncateThreshold = 0;// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.// Uncomment the following to use the old assertions:// const Test = require("@codewars/test-compat");- import codewars_test as test
- from solution import dumbRockPaperScissors
describe('dumbRockPaperScissors', function() {it('returns "Draw" for Rock vs Rock', function() {assert.strictEqual(dumbRockPaperScissors('Rock', 'Rock'), 'Draw');});it('returns "Draw" for Paper vs Paper', function() {assert.strictEqual(dumbRockPaperScissors('Paper', 'Paper'), 'Draw');});it('returns "Draw" for Scissors vs Scissors', function() {assert.strictEqual(dumbRockPaperScissors('Scissors', 'Scissors'), 'Draw');});it('returns "Player 1 wins" for Rock vs Scissors', function() {assert.strictEqual(dumbRockPaperScissors('Rock', 'Scissors'), 'Player 1 wins');});it('returns "Player 1 wins" for Scissors vs Paper', function() {assert.strictEqual(dumbRockPaperScissors('Scissors', 'Paper'), 'Player 1 wins');});it('returns "Player 1 wins" for Paper vs Rock', function() {assert.strictEqual(dumbRockPaperScissors('Paper', 'Rock'), 'Player 1 wins');});it('returns "Player 2 wins" for Scissors vs Rock', function() {assert.strictEqual(dumbRockPaperScissors('Scissors', 'Rock'), 'Player 2 wins');});it('returns "Player 2 wins" for Paper vs Scissors', function() {assert.strictEqual(dumbRockPaperScissors('Paper', 'Scissors'), 'Player 2 wins');});it('returns "Player 2 wins" for Rock vs Paper', function() {assert.strictEqual(dumbRockPaperScissors('Rock', 'Paper'), 'Player 2 wins');});});- @test.describe("dumbRockPaperScissors")
- def fixed_tests():
- @test.it('Basic Test Cases')
- def basic_test_cases():
- test.assert_equals(dumbRockPaperScissors('Rock', 'Rock'),'Draw')
- test.assert_equals(dumbRockPaperScissors('Rock', 'Paper'),'Player 2 wins')
- test.assert_equals(dumbRockPaperScissors('Paper', 'Rock'),'Player 1 wins')
- test.assert_equals(dumbRockPaperScissors('Paper', 'Paper'),'Draw')
- test.assert_equals(dumbRockPaperScissors('Rock', 'Scissors'),'Player 1 wins')
- test.assert_equals(dumbRockPaperScissors('Paper', 'Scissors'),'Player 2 wins')
- test.assert_equals(dumbRockPaperScissors('Scissors', 'Rock'),'Player 2 wins')
- test.assert_equals(dumbRockPaperScissors('Scissors', 'Paper'),'Player 1 wins')
- test.assert_equals(dumbRockPaperScissors('Scissors', 'Scissors'),'Draw')