-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
003cdb8
commit 5059623
Showing
6 changed files
with
414 additions
and
16 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import random | ||
from enum import Enum | ||
|
||
LEFT_WINS = 1 | ||
RIGHT_WINS = -1 | ||
DRAW = 0 | ||
|
||
|
||
def compare(hand1, hand2): | ||
return hand1 > hand2 | ||
|
||
|
||
class Hand(Enum): | ||
ROCK = 1 | ||
PAPER = 2 | ||
SCISSORS = 3 | ||
|
||
def __lt__(self, other): | ||
if self.value == other.value: | ||
return DRAW | ||
if self.value - other.value == 1 or self.value - other.value == -2: | ||
return RIGHT_WINS | ||
return LEFT_WINS | ||
|
||
|
||
class RandomPlayer(): | ||
def next_hand(self): | ||
r = random.random() | ||
if r > 0.66: | ||
return Hand.ROCK | ||
elif r > 0.33: | ||
return Hand.PAPER | ||
else: | ||
return Hand.SCISSORS | ||
|
||
|
||
class Game(): | ||
def play(self, player1, player2): | ||
for _ in range(10): | ||
hand1 = player1.next_hand() | ||
hand2 = player2.next_hand() | ||
winlose = compare(hand1, hand2) | ||
if winlose != DRAW: | ||
return winlose | ||
return DRAW |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
def isSemVer(ver): | ||
import re | ||
numeric = '(0|[1-9][0-9]*)' | ||
pattern = r'^%s.%s.%s$' % (numeric, numeric, numeric) | ||
return re.match(pattern, ver) != None |
Oops, something went wrong.