This commit is contained in:
William Mantly 2016-02-23 17:46:32 -05:00
parent 1ee37b4023
commit 26469c9ae3
6 changed files with 81 additions and 53 deletions

View File

@ -9,8 +9,11 @@ class Controller:
def start(self):
selected = int( self.view.display_doors() )
self.doors = Doors( selected, self.name )
selected = False
while selected not in ['1', '2', '3']:
selected = self.view.display_doors()
self.doors = Doors(int(selected), self.name)
self.host_twist()
@ -23,30 +26,32 @@ class Controller:
for i in range(1, 4):
if i == self.doors.selected:
message += "[ X ] "
message += '[ X ] '
elif i == self.doors.open_door:
message += "[ Goat ] "
message += '[ Goat ] '
else:
message += "[ " + str(i) + " ] "
message += '[ ' + str(i) + ' ] '
other_selection = i
selection = False
while selection not in ['n', 'y', '']:
selection = self.view.host_twist(message).lower()
selection = self.view.host_twist( message )
if selection:
if selection == 'y':
self.doors.selected = other_selection
self.doors.switch = True
return self.out_come()
def out_come(self):
message = 'LOSE'
if self.doors.out_come():
do = self.view.winner()
else:
do = self.view.loser()
message = 'WIN'
if do == 'n':
exit()
replay = self.view.out_come(message)
self.start()
return True
if replay in ['', 'y']:
return self.start()
return exit()
if __name__ == '__main__':
Controller()

View File

@ -1,5 +1,9 @@
import sqlite3
import random
conn = sqlite3.connect('default.db')
c = conn.cursor()
class Doors:
def __init__(self, selected, name):
self.name = name
@ -24,10 +28,7 @@ class Doors:
return False
def logDB(name, switch, outcome):
import sqlite3
conn = sqlite3.connect('default.db')
c = conn.cursor()
c.execute("INSERT INTO games (name, switch, outcome) values (?,?,?) ", (name, switch, outcome))
@ -35,3 +36,24 @@ def logDB( name, switch, outcome ):
conn.close()
return True
def seedDB():
c.execute("""
CREATE TABLE games (
id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT DEFAULT NULL,
switch TEXT DEFAULT NULL,
outcome TEXT DEFAULT NULL
);
""")
conn.commit()
conn.close()
if __name__ == '__main__':
seed = input('Seed the database[y/n]: ').lower()
if seed in ['y', 'yes']:
print('seeding')
seedDB()
exit()

View File

@ -1,24 +1,25 @@
class View:
def __init__( self ):
print( "Welcome to the Monty Hall Problem!")
def get_name(self):
return input( "Please enter your name: " )
print('\033c')
print('Welcome to the Monty Hall Problem!')
return input('Please enter your name: ')
def display_doors(self):
print('\033c')
print('Doors: [ 1 ] [ 2 ] [ 3 ]')
return input('Select door: ')
def host_twist(self, message):
print( "The host will revel where one goat is..." )
print('The host will revel where one goat is...')
print(message)
print( "Would you like to change your selection? [n/y]" )
return input( "[no]: ")
print('Would you like to change your selection? [n/y]')
return input('[n]: ')
def winner( self ):
print( "You WIN!!!" )
return input("Play again?[y]")
def out_come(self, message):
print('You {}!!!'.format(message))
return input('Play again?[y]')
if __name__ == '__main__':
print('Please opne controller.py')
exit()
def loser( self ):
print( "You Lose!!!" )
return input("Play again?[y]")