Skip to content

Commit

Permalink
Update hanoe.py
Browse files Browse the repository at this point in the history
2.1; 2.3;  3.1
  • Loading branch information
MrCoppelius committed Apr 14, 2016
1 parent 4b06984 commit 816413d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions hanoe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env python3
#!/usr/bin/env python3

import re, copy, sys
import AI
import os
import os.path
import time


#Вместо len лучше было бы вставить hoops_number
Expand Down Expand Up @@ -39,12 +42,13 @@ class Game:

mov_cmd = re.compile('\d+')

def __init__(self, ai = None, who = "Player", lvl = 5, istream = input, ostream = print):
def __init__(self, ai = None, who = "Player", lvl = 5, istream = input, ostream = print, delay = 0):
self.status = "Runing"
self.who = who
self.istream = istream
self.ai = ai
self.lvl = lvl
self.delay = delay
self.count = 0
arr = list(range(lvl+1))[1:]
arr.reverse()
Expand All @@ -55,6 +59,7 @@ def __init__(self, ai = None, who = "Player", lvl = 5, istream = input, ostream
]
self.win_combination = arr


def process(self):
#(user_input[0] != "exit" or user_input[0] != "e") and
while( self.status == "Runing"):
Expand Down Expand Up @@ -84,6 +89,8 @@ def process(self):
print ("AI FAILED (FORBIDDEN MOVE)")
self.situation()
def draw(self):
os.system('cls')

print ("COUNT: " + str(self.count) )
print ("| "*3)
for g in range(self.lvl):
Expand All @@ -93,14 +100,16 @@ def draw(self):
except IndexError:
print("|", end=" ")
print()
time.sleep(self.delay)
def situation(self):
#self.count+=1
self.draw()
if self.pyramids[2] == self.win_combination:
self.status = "Win"
print ("YOU WIN")
for i in range(1,len(self.pyramids)):
if self.pyramids[i] == self.win_combination:
self.status = "Win"
print ("YOU WIN")


if __name__ == "__main__":
if '--help' in sys.argv:
print(u"\nПРАВИЛА:")
Expand All @@ -125,8 +134,14 @@ def situation(self):
print(u"Если вы хотите получить информацию о первой пирамиде, то N = 0\n")
print(u"УДАЧИ!\n")
exit()

elif '--ai' in sys.argv:
game = Game(who = "AI", ai = AI.AI)
if '--delay' in sys.argv:
#if sys.argv[2].isdigit():
delay = int(sys.argv[3])
game = Game(who = "AI", ai = AI.AI, delay=delay)
else: game = Game(who = "AI", ai = AI.AI)

else: game = Game()
game.draw()
game.process()

0 comments on commit 816413d

Please sign in to comment.