import Solitaire import tensorflow as tf import numpy as np from sklearn.model_selection import train_test_split #training_games() games, labels = Solitaire.create_batched_training_data('training_dataV3.txt') train_X, test_X, train_Y, test_Y = train_test_split(games, labels, test_size=0.33, random_state=42) Coord_to_one_hot, One_hot_to_Coord = Solitaire.label_to_one_hot() input_layer_size = 33 classes = 76 epochs = 10000 x = tf.placeholder('float', [None, input_layer_size]) y = tf.placeholder('float', [None, classes]) # def Fully_Connected_Layer(inputs,channels_in ,channels_out, NameScope = '',activation = True): # with tf.name_scope(NameScope): # hidden_layer = {'Weights': tf.Variable(tf.random_normal([channels_in,channels_out]),'float',name = 'W'), # 'Biases' :tf.Variable(tf.random_normal([channels_out]),'float', name = 'B')} # tf.summary.histogram("weights", hidden_layer['Weights']) # tf.summary.histogram("biases", hidden_layer['Biases'])
def setUp(self): self.myDeck = Deck() self.myGame = Solitaire()
class TestSolitaire(unittest.TestCase): # use any meaningful name def setUp(self): self.myDeck = Deck() self.myGame = Solitaire() def testMoveBetweenTableau(self): cardList=self.myGame.tableau[2] cards=cardList[-1:] #Move one card self.myGame.moveBetweenTableau(1,2,3) self.assertTrue(cards[-1] in self.myGame.tableau[3]) self.assertEqual(1,len(self.myGame.tableau[2])) self.assertEqual(4,len(self.myGame.tableau[3])) #Move 5 cards cardList2=self.myGame.tableau[6] cards2=cardList2[-5:] self.myGame.moveBetweenTableau(5,6,1) self.assertTrue(cards2[-1] in self.myGame.tableau[1]) self.assertTrue(cards2[-4] in self.myGame.tableau[1]) self.assertTrue(cards2[-5] in self.myGame.tableau[1]) self.assertTrue(cards2[-2] in self.myGame.tableau[1]) self.assertTrue(cards2[-3] in self.myGame.tableau[1]) self.assertEqual(6,len(self.myGame.tableau[1])) self.assertEqual(1,len(self.myGame.tableau[6])) def testmoveTableauToFoundation(self): #Move from Tableau 1 to Foundation 1: cardList=self.myGame.tableau[1] card=cardList[-1] self.myGame.moveTableauToFoundation(1,1) self.assertEqual([],self.myGame.tableau[1]) self.assertTrue(card in self.myGame.foundation[1]) self.assertFalse(card in self.myGame.tableau[1]) #Move from Tableau 6 to Foundation 4: cardList2=self.myGame.tableau[6] card2=cardList2[-1] self.myGame.moveTableauToFoundation(6,4) self.assertTrue(card2 in self.myGame.foundation[4]) self.assertFalse(card2 in self.myGame.tableau[6]) def testMoveWasteToTableau(self): self.myGame.drawFromDeck() #Draw a card from the deck to fill the waste card=self.myGame.waste[-1] self.myGame.moveWasteToTableau(7) #Check whether the card from waste moved to Tableau 7 self.assertTrue(card in self.myGame.tableau[7]) def testMoveWasteToFoundation(self): self.myGame.drawFromDeck() card=self.myGame.waste[-1] self.myGame.moveWasteToFoundation(2) self.assertTrue(card in self.myGame.foundation[2]) def testDrawFromDeck(self): #Draw 2 cards self.myGame.drawFromDeck() self.myGame.drawFromDeck() self.assertEqual(2,len(self.myGame.waste)) self.myGame.drawFromDeck() self.myGame.drawFromDeck() self.myGame.drawFromDeck() self.myGame.drawFromDeck() #Draw 4 more cards self.assertEqual(6,len(self.myGame.waste)) def testFlipWaste(self): self.myGame.drawFromDeck() self.myGame.drawFromDeck() card1=self.myGame.waste[-1] card2=self.myGame.waste[-2] self.myGame.flipWaste() #Check Wste is empty self.assertEqual([],self.myGame.waste) #Check the cards are not present self.assertFalse(card1 in self.myGame.waste) self.assertFalse(card2 in self.myGame.waste) def testCheckIfWon(self): ls=self.myGame.foundation.values() #Initially We don't win as Foundation does not have 52 cards, all ordered by suit and rank self.assertEqual(False,self.myGame.checkIfWon()) self.myGame.foundation = {1:range(0,13),2:range(13,26),3:range(26,39),4:range(39,52)} self.assertTrue(self.myGame.checkIfWon()) def testDetermineFunctionType(self): #Blank Input input1='' self.assertEqual(0,self.myGame.determineFunctionType(input1)) #Restart command input2='r' self.assertEqual(3,self.myGame.determineFunctionType(input2)) #Get input command input3='g' self.assertEqual(1,self.myGame.determineFunctionType(input3)) #Move command input4='m t54 t6' self.assertEqual(2,self.myGame.determineFunctionType(input4)) def testDetermineMoveType(self): #Tableau to Tableau move type string1='m t[1,2] t6' self.assertEqual(1,self.myGame.determineMoveType(string1)) #Tableau to Foundation move type string2='m t[3] f2' self.assertEqual(2,self.myGame.determineMoveType(string2)) #Waste to Tableau move type string3='m w t3' self.assertEqual(3,self.myGame.determineMoveType(string3)) #Waste to Foundation move type string4='m wf1' self.assertEqual(4,self.myGame.determineMoveType(string4)) #Invalid Move type string5='m t45 o9' self.assertEqual(0,self.myGame.determineMoveType(string5)) #Invalid Input type string6='filjslkln 889op' self.assertEqual(0,self.myGame.determineMoveType(string6)) def testWasteString(self): #Empty Waste self.assertEqual(" ",self.myGame.wasteString()) #Fill 2 cards in the waste and print the top card self.myGame.drawFromDeck() self.myGame.drawFromDeck() wasteList=self.myGame.waste wasteCard=wasteList[-1] if type(wasteCard.rank)==int: self.assertEqual(str(wasteCard.rank)+wasteCard.suit.upper(),self.myGame.wasteString()) else: self.assertEqual(str(wasteCard.rank.upper())+wasteCard.suit.upper(),self.myGame.wasteString()) def testDeckString(self): #Card of the deck is hidden so it should print xx self.assertEqual('xx',self.myGame.deckString()) self.myGame.mainDeck = [] self.assertEqual(' ',self.myGame.deckString()) def testFoundationString(self): self.assertEqual(self.myGame.foundationString()," ") self.myGame.moveTableauToFoundation(5,1) self.myGame.moveTableauToFoundation(3,1) cardList=self.myGame.foundation.values() firstList=cardList[0] topCard = firstList[-1] x = topCard.__str__() self.assertEqual(self.myGame.foundationString()," " + x + " ") def testGetValues(self): self.assertEqual([10,7,2],self.myGame.getValues('m t10,7 t2',1)) self.assertEqual([6,7],self.myGame.getValues('m t6 t7',2)) self.assertEqual([1],self.myGame.getValues('m w t1',3)) self.assertEqual([2],self.myGame.getValues('m wf2',4)) def testgetValuesWasteMove(self): #Waste to Tableau Move self.assertEqual([2],self.myGame.getValuesWasteMove('mw[]t2')) #Waste to Foundation Move self.assertEqual([2],self.myGame.getValuesWasteMove('m:wf2')) def testGetValuesFoundationMove(self): #Move from Tableau to foundation self.assertEqual([7,2],self.myGame.getValuesFoundationMove('m t7:f2')) self.assertEqual([1,4],self.myGame.getValuesFoundationMove('m t1f(4)')) def testGetValuesTableauMove(self): #Two Digit Case self.assertEqual([12,6,2],self.myGame.getValuesTableauMove('m t12,6t2')) #One Digit Case self.assertEqual([1,5,3],self.myGame.getValuesTableauMove('m t1,5t[3]')) def testCheckMoveInputValid(self): #Moving between Tableaux self.assertEqual(False,self.myGame.checkMoveInputValid('m t1f t6(4)',1)) self.assertEqual(True,self.myGame.checkMoveInputValid('m t[1,7] t4',1)) self.assertEqual(False,self.myGame.checkMoveInputValid('m t15 f4',2)) self.assertEqual(True,self.myGame.checkMoveInputValid('m t5 f3',2)) #Moving from Waste to Tableau self.assertEqual(False,self.myGame.checkMoveInputValid('mw3 t6(4)',3)) self.assertEqual(True,self.myGame.checkMoveInputValid('m w t4',3)) #Move Waste to foundation self.assertEqual(True,self.myGame.checkMoveInputValid('m w f1',4)) self.assertEqual(False,self.myGame.checkMoveInputValid('mw3f3',4)) def testCheckWasteMoveValid(self): #We are assuming the the user has entered a waste move type input. We want to check the format. self.assertEqual(True,self.myGame.checkWasteMoveValid('m w f1')) self.assertEqual(False,self.myGame.checkWasteMoveValid('m w f71')) self.assertEqual(True,self.myGame.checkWasteMoveValid('m w f3')) self.assertEqual(False,self.myGame.checkWasteMoveValid('m w6 f1')) def testCheckTableauMoveValid(self): #We are assuming the the user has entered a tableau to tableau move type input. We want to check the format. self.assertEqual(True,self.myGame.checkTableuMoveValid('m t[5,6] t7')) self.assertEqual(False,self.myGame.checkTableuMoveValid('m t5 t7')) self.assertEqual(True,self.myGame.checkTableuMoveValid('m t3,4 f2')) self.assertEqual(False,self.myGame.checkTableuMoveValid('m t3,4 f80')) def testCheckFoundationMoveValid(self): #We are assuming the the user has entered a tableau to foundation move type input. We want to check the format. self.assertEqual(True,self.myGame.checkFoundationMoveValid('m t5 f3')) self.assertEqual(False,self.myGame.checkFoundationMoveValid('m t57f2')) self.assertEqual(True,self.myGame.checkFoundationMoveValid('m t[3] f1')) self.assertEqual(False,self.myGame.checkFoundationMoveValid('m t3,4 f80')) def testGetNumbers(self): self.assertEqual(self.myGame.getNumbers('3432gfds1 n %^,^&$'),[3,4,3,2,1,',']) def testGetLetters(self): self.assertEqual(self.myGame.getLetters('234b43534,,5'),['b']) def testRemoveSpaces(self): self.assertEqual(self.myGame.removeSpaces(' m w t[]1,4'),'mwt1,4') def testIsInt(self): self.assertTrue(self.myGame.isInt(1)) self.assertFalse(self.myGame.isInt('f')) def testCheckLegalTableauMove(self): self.myGame.tableau = {2:[],3:[],4:[],5:[],6:[]} self.myGame.tableau[1] = [Card(10,'h'),Card(7,'c')] self.myGame.tableau[7] = [Card(5,'c'),Card(1,'d'),Card(8,'h')] self.assertTrue(self.myGame.checkLegalTableauMove(1,1,7)) self.assertFalse(self.myGame.checkLegalTableauMove(1,7,1)) self.assertFalse(self.myGame.checkLegalTableauMove(1,2,1)) self.assertFalse(self.myGame.checkLegalTableauMove(1,1,2)) self.assertFalse(self.myGame.checkLegalTableauMove(2,7,2)) self.assertFalse(self.myGame.checkLegalTableauMove(1,1,1)) def testCheckLegalTableauFoundationMove(self): self.myGame.tableau = {2:[],3:[],4:[],5:[],6:[]} self.myGame.tableau[1] = [Card(10,'h'),Card(7,'c'),Card(1,'c')] self.myGame.tableau[2] = [Card(4,'c')] self.myGame.tableau[7] = [Card(5,'c'),Card(1,'d'),Card(8,'h')] self.myGame.foundation = {1:[],2:[Card(6,'h'),Card(7,'h')],3:[],4:[Card(3,'c')]} self.assertTrue(self.myGame.checkLegalTableauFoundationMove(2,4)) self.assertTrue(self.myGame.checkLegalTableauFoundationMove(1,1)) self.assertFalse(self.myGame.checkLegalTableauFoundationMove(7,1)) self.assertTrue(self.myGame.checkLegalTableauFoundationMove(2,4)) def testCheckLegalWasteFoundationMove(self): self.myGame.foundation = {1:[],2:[Card(6,'h'),Card(7,'h')],3:[],4:[Card(3,'c')]} self.myGame.waste = [] self.assertFalse(self.myGame.checkLegalWasteFoundationMove(1)) self.myGame.waste = [Card(2,'c'),Card(1,'h')] self.assertTrue(self.myGame.checkLegalWasteFoundationMove(1)) self.myGame.waste = [Card(2,'c'),Card(4,'c')] self.assertTrue(self.myGame.checkLegalWasteFoundationMove(4)) self.assertFalse(self.myGame.checkLegalWasteFoundationMove(3)) def testCheckLegalWasteTableauMove(self): self.myGame.tableau = {2:[],3:[],4:[],5:[],6:[]} self.myGame.tableau[1] = [Card(10,'h'),Card(7,'c'),Card(1,'c')] self.myGame.tableau[2] = [Card(4,'c')] self.myGame.tableau[7] = [Card(5,'c'),Card(1,'d'),Card(8,'h')] self.myGame.waste = [] self.assertFalse(self.myGame.checkLegalWasteTableauMove(1)) self.myGame.waste = [Card(7,'c')] self.assertTrue(self.myGame.checkLegalWasteTableauMove(7)) self.assertFalse(self.myGame.checkLegalWasteTableauMove(3)) self.myGame.waste = [Card(2,'c'),Card(13,'c')] self.assertTrue(self.myGame.checkLegalWasteTableauMove(3)) def testExecuteMove(self): self.myGame.tableau = {2:[],3:[],4:[],5:[],6:[]} self.myGame.tableau[1] = [Card(10,'h'),Card(7,'c'),Card(1,'c')] self.myGame.waste= [Card(10,'h'),Card(1,'s')] cardlist=self.myGame.tableau[1] card=cardlist[-1] self.myGame.tableau[2] = [Card(4,'c')] self.myGame.tableau[7] = [Card(5,'c'),Card(1,'d'),Card(8,'h')] self.myGame.foundation = {1:[],2:[Card(6,'h'),Card(7,'h')],3:[],4:[Card(3,'c')]} self.myGame.waste = [Card(2,'c'),Card(7,'c')] self.myGame.executeMove(1,[1,1,2]) self.assertIn(card,self.myGame.tableau[2]) self.assertNotIn(card,self.myGame.tableau[1]) cardlist=self.myGame.tableau[7] card=cardlist[-1] self.myGame.executeMove(2,[7,1]) self.assertIn(card,self.myGame.foundation[1]) self.assertNotIn(card,self.myGame.tableau[7]) card=self.myGame.waste[-1] self.myGame.executeMove(3,[7]) self.assertIn(card,self.myGame.tableau[7]) self.assertNotIn(card,self.myGame.waste) card=self.myGame.waste[-1] self.myGame.executeMove(4,[4]) self.assertIn(card,self.myGame.foundation[4]) self.assertNotIn(card,self.myGame.waste)
def game_loop(): run_game = True user_game = 0 while run_game: if user_game == 0: display_main_menu = True # Pre render text and other shapes # The header text / bounding rectangle header_text = HEADER_FONT.render('Choose a game to play!', True, BLACK) # Creates a surface for this text to be drawn on the screen header_rect = header_text.get_rect() # Gets the rectantgle surroudnign the text header_rect_x = ( DISPLAY_WIDTH / 2) - header_rect.centerx # Subtract the center of the screen with the center of the texts' rectangle to display the text in the center of the screen header_rect_y = 50 - header_rect.centery # Same concept here except not half the screen, only a few pixels below the top of the screen (y=0) # header_width = header_rect.width # header_height = header_rect.height # Solitaire text and bounding rectangle sol_text = BUTTON_FONT.render('Solitaire', True, BLACK) sol_rect = sol_text.get_rect() sol_rect_x = (DISPLAY_WIDTH / 2) - sol_rect.centerx sol_rect_y = 200 - sol_rect.centery # increment buttons by 100px apart sol_width = sol_rect.width sol_height = sol_rect.height # The final rectangle has some added padding, so must save it as its own! sol_final_rect = ((sol_rect_x - (BUTTON_WIDTH_PADDING / 2)), (sol_rect_y - (BUTTON_HEIGHT_PADDING / 2)), (sol_width + BUTTON_WIDTH_PADDING), (sol_height + BUTTON_HEIGHT_PADDING)) # Black jack text and bounding rectangle bj_text = BUTTON_FONT.render('Black jack', True, BLACK) bj_rect = bj_text.get_rect() bj_rect_x = (DISPLAY_WIDTH / 2) - bj_rect.centerx bj_rect_y = 300 - bj_rect.centery bj_width = bj_rect.width bj_height = bj_rect.height bj_final_rect = ((bj_rect_x - (BUTTON_WIDTH_PADDING / 2)), (bj_rect_y - (BUTTON_HEIGHT_PADDING / 2)), (bj_width + BUTTON_WIDTH_PADDING), (bj_height + BUTTON_HEIGHT_PADDING)) # gin Rummy text and bounding rectangle gr_text = BUTTON_FONT.render('Gin rummy', True, BLACK) gr_rect = gr_text.get_rect() gr_rect_x = (DISPLAY_WIDTH / 2) - gr_rect.centerx gr_rect_y = 400 - gr_rect.centery gr_width = gr_rect.width gr_height = gr_rect.height gr_final_rect = ((gr_rect_x - (BUTTON_WIDTH_PADDING / 2)), (gr_rect_y - (BUTTON_HEIGHT_PADDING / 2)), (gr_width + BUTTON_WIDTH_PADDING), (gr_height + BUTTON_HEIGHT_PADDING)) # Main menu loop while display_main_menu: for event in pygame.event.get(): # loops through the events gathered by pygame if event.type == pygame.QUIT or event.type == KEYUP: # Escape key to quit, mostly to speed up testing/development # If the window is closed, shutdown all of pygame and don't run the next function # which is what would happen if display_main_menu was set to true if event.key is K_ESCAPE: pygame.quit() quit() elif event.type == MOUSEBUTTONUP: # When the mouse is released mouse_location = pygame.mouse.get_pos() # Get the current location # Check if the location of that click collided with any of the rectangles that were created above if Rect(sol_final_rect).collidepoint(mouse_location): # Create a Rect object so that we can access the collidepoint() function display_main_menu = False # Stops the loop from running, letting us move into the game loop user_game = 1 # Sets the game the user wants to play, broken down by a unique number elif Rect(bj_final_rect).collidepoint(mouse_location): display_main_menu = False user_game = 2 elif Rect(gr_final_rect).collidepoint(mouse_location): display_main_menu = False user_game = 3 # Draw/"blit" stuff here game_display.blit(bg, (0, 0)) # Draws the background image to the background # Header # pygame.draw.rect(game_display, WHITE, (header_rect_x, header_rect_y, header_width, header_height)) # Don't really need to show game_display.blit(header_text, (header_rect_x, header_rect_y)) # Write the text to the screen # Solitaire button pygame.draw.rect(game_display, BLACK, sol_final_rect, 1) game_display.blit(sol_text, (sol_rect_x, sol_rect_y)) # Black jack button pygame.draw.rect(game_display, BLACK, bj_final_rect, 1) game_display.blit(bj_text, (bj_rect_x, bj_rect_y)) # Gin rummy button pygame.draw.rect(game_display, BLACK, gr_final_rect, 1) game_display.blit(gr_text, (gr_rect_x, gr_rect_y)) # Update the screen pygame.display.update() elif user_game == 1: Solitaire.run(game_display) elif user_game == 2: pygame.quit() Blackjack.main() elif user_game == 3: pygame.quit() GinRummy.main()
def setUp(self): self.myDeck = Deck() self.myGame = Solitaire()
class TestSolitaire(unittest.TestCase): # use any meaningful name def setUp(self): self.myDeck = Deck() self.myGame = Solitaire() def testMoveBetweenTableau(self): cardList = self.myGame.tableau[2] cards = cardList[-1:] #Move one card self.myGame.moveBetweenTableau(1, 2, 3) self.assertTrue(cards[-1] in self.myGame.tableau[3]) self.assertEqual(1, len(self.myGame.tableau[2])) self.assertEqual(4, len(self.myGame.tableau[3])) #Move 5 cards cardList2 = self.myGame.tableau[6] cards2 = cardList2[-5:] self.myGame.moveBetweenTableau(5, 6, 1) self.assertTrue(cards2[-1] in self.myGame.tableau[1]) self.assertTrue(cards2[-4] in self.myGame.tableau[1]) self.assertTrue(cards2[-5] in self.myGame.tableau[1]) self.assertTrue(cards2[-2] in self.myGame.tableau[1]) self.assertTrue(cards2[-3] in self.myGame.tableau[1]) self.assertEqual(6, len(self.myGame.tableau[1])) self.assertEqual(1, len(self.myGame.tableau[6])) def testmoveTableauToFoundation(self): #Move from Tableau 1 to Foundation 1: cardList = self.myGame.tableau[1] card = cardList[-1] self.myGame.moveTableauToFoundation(1, 1) self.assertEqual([], self.myGame.tableau[1]) self.assertTrue(card in self.myGame.foundation[1]) self.assertFalse(card in self.myGame.tableau[1]) #Move from Tableau 6 to Foundation 4: cardList2 = self.myGame.tableau[6] card2 = cardList2[-1] self.myGame.moveTableauToFoundation(6, 4) self.assertTrue(card2 in self.myGame.foundation[4]) self.assertFalse(card2 in self.myGame.tableau[6]) def testMoveWasteToTableau(self): self.myGame.drawFromDeck( ) #Draw a card from the deck to fill the waste card = self.myGame.waste[-1] self.myGame.moveWasteToTableau(7) #Check whether the card from waste moved to Tableau 7 self.assertTrue(card in self.myGame.tableau[7]) def testMoveWasteToFoundation(self): self.myGame.drawFromDeck() card = self.myGame.waste[-1] self.myGame.moveWasteToFoundation(2) self.assertTrue(card in self.myGame.foundation[2]) def testDrawFromDeck(self): #Draw 2 cards self.myGame.drawFromDeck() self.myGame.drawFromDeck() self.assertEqual(2, len(self.myGame.waste)) self.myGame.drawFromDeck() self.myGame.drawFromDeck() self.myGame.drawFromDeck() self.myGame.drawFromDeck() #Draw 4 more cards self.assertEqual(6, len(self.myGame.waste)) def testFlipWaste(self): self.myGame.drawFromDeck() self.myGame.drawFromDeck() card1 = self.myGame.waste[-1] card2 = self.myGame.waste[-2] self.myGame.flipWaste() #Check Wste is empty self.assertEqual([], self.myGame.waste) #Check the cards are not present self.assertFalse(card1 in self.myGame.waste) self.assertFalse(card2 in self.myGame.waste) def testCheckIfWon(self): ls = self.myGame.foundation.values() #Initially We don't win as Foundation does not have 52 cards, all ordered by suit and rank self.assertEqual(False, self.myGame.checkIfWon()) self.myGame.foundation = { 1: range(0, 13), 2: range(13, 26), 3: range(26, 39), 4: range(39, 52) } self.assertTrue(self.myGame.checkIfWon()) def testDetermineFunctionType(self): #Blank Input input1 = '' self.assertEqual(0, self.myGame.determineFunctionType(input1)) #Restart command input2 = 'r' self.assertEqual(3, self.myGame.determineFunctionType(input2)) #Get input command input3 = 'g' self.assertEqual(1, self.myGame.determineFunctionType(input3)) #Move command input4 = 'm t54 t6' self.assertEqual(2, self.myGame.determineFunctionType(input4)) def testDetermineMoveType(self): #Tableau to Tableau move type string1 = 'm t[1,2] t6' self.assertEqual(1, self.myGame.determineMoveType(string1)) #Tableau to Foundation move type string2 = 'm t[3] f2' self.assertEqual(2, self.myGame.determineMoveType(string2)) #Waste to Tableau move type string3 = 'm w t3' self.assertEqual(3, self.myGame.determineMoveType(string3)) #Waste to Foundation move type string4 = 'm wf1' self.assertEqual(4, self.myGame.determineMoveType(string4)) #Invalid Move type string5 = 'm t45 o9' self.assertEqual(0, self.myGame.determineMoveType(string5)) #Invalid Input type string6 = 'filjslkln 889op' self.assertEqual(0, self.myGame.determineMoveType(string6)) def testWasteString(self): #Empty Waste self.assertEqual(" ", self.myGame.wasteString()) #Fill 2 cards in the waste and print the top card self.myGame.drawFromDeck() self.myGame.drawFromDeck() wasteList = self.myGame.waste wasteCard = wasteList[-1] if type(wasteCard.rank) == int: self.assertEqual( str(wasteCard.rank) + wasteCard.suit.upper(), self.myGame.wasteString()) else: self.assertEqual( str(wasteCard.rank.upper()) + wasteCard.suit.upper(), self.myGame.wasteString()) def testDeckString(self): #Card of the deck is hidden so it should print xx self.assertEqual('xx', self.myGame.deckString()) self.myGame.mainDeck = [] self.assertEqual(' ', self.myGame.deckString()) def testFoundationString(self): self.assertEqual(self.myGame.foundationString(), " ") self.myGame.moveTableauToFoundation(5, 1) self.myGame.moveTableauToFoundation(3, 1) cardList = self.myGame.foundation.values() firstList = cardList[0] topCard = firstList[-1] x = topCard.__str__() self.assertEqual(self.myGame.foundationString(), " " + x + " ") def testGetValues(self): self.assertEqual([10, 7, 2], self.myGame.getValues('m t10,7 t2', 1)) self.assertEqual([6, 7], self.myGame.getValues('m t6 t7', 2)) self.assertEqual([1], self.myGame.getValues('m w t1', 3)) self.assertEqual([2], self.myGame.getValues('m wf2', 4)) def testgetValuesWasteMove(self): #Waste to Tableau Move self.assertEqual([2], self.myGame.getValuesWasteMove('mw[]t2')) #Waste to Foundation Move self.assertEqual([2], self.myGame.getValuesWasteMove('m:wf2')) def testGetValuesFoundationMove(self): #Move from Tableau to foundation self.assertEqual([7, 2], self.myGame.getValuesFoundationMove('m t7:f2')) self.assertEqual([1, 4], self.myGame.getValuesFoundationMove('m t1f(4)')) def testGetValuesTableauMove(self): #Two Digit Case self.assertEqual([12, 6, 2], self.myGame.getValuesTableauMove('m t12,6t2')) #One Digit Case self.assertEqual([1, 5, 3], self.myGame.getValuesTableauMove('m t1,5t[3]')) def testCheckMoveInputValid(self): #Moving between Tableaux self.assertEqual(False, self.myGame.checkMoveInputValid('m t1f t6(4)', 1)) self.assertEqual(True, self.myGame.checkMoveInputValid('m t[1,7] t4', 1)) self.assertEqual(False, self.myGame.checkMoveInputValid('m t15 f4', 2)) self.assertEqual(True, self.myGame.checkMoveInputValid('m t5 f3', 2)) #Moving from Waste to Tableau self.assertEqual(False, self.myGame.checkMoveInputValid('mw3 t6(4)', 3)) self.assertEqual(True, self.myGame.checkMoveInputValid('m w t4', 3)) #Move Waste to foundation self.assertEqual(True, self.myGame.checkMoveInputValid('m w f1', 4)) self.assertEqual(False, self.myGame.checkMoveInputValid('mw3f3', 4)) def testCheckWasteMoveValid(self): #We are assuming the the user has entered a waste move type input. We want to check the format. self.assertEqual(True, self.myGame.checkWasteMoveValid('m w f1')) self.assertEqual(False, self.myGame.checkWasteMoveValid('m w f71')) self.assertEqual(True, self.myGame.checkWasteMoveValid('m w f3')) self.assertEqual(False, self.myGame.checkWasteMoveValid('m w6 f1')) def testCheckTableauMoveValid(self): #We are assuming the the user has entered a tableau to tableau move type input. We want to check the format. self.assertEqual(True, self.myGame.checkTableuMoveValid('m t[5,6] t7')) self.assertEqual(False, self.myGame.checkTableuMoveValid('m t5 t7')) self.assertEqual(True, self.myGame.checkTableuMoveValid('m t3,4 f2')) self.assertEqual(False, self.myGame.checkTableuMoveValid('m t3,4 f80')) def testCheckFoundationMoveValid(self): #We are assuming the the user has entered a tableau to foundation move type input. We want to check the format. self.assertEqual(True, self.myGame.checkFoundationMoveValid('m t5 f3')) self.assertEqual(False, self.myGame.checkFoundationMoveValid('m t57f2')) self.assertEqual(True, self.myGame.checkFoundationMoveValid('m t[3] f1')) self.assertEqual(False, self.myGame.checkFoundationMoveValid('m t3,4 f80')) def testGetNumbers(self): self.assertEqual(self.myGame.getNumbers('3432gfds1 n %^,^&$'), [3, 4, 3, 2, 1, ',']) def testGetLetters(self): self.assertEqual(self.myGame.getLetters('234b43534,,5'), ['b']) def testRemoveSpaces(self): self.assertEqual(self.myGame.removeSpaces(' m w t[]1,4'), 'mwt1,4') def testIsInt(self): self.assertTrue(self.myGame.isInt(1)) self.assertFalse(self.myGame.isInt('f')) def testCheckLegalTableauMove(self): self.myGame.tableau = {2: [], 3: [], 4: [], 5: [], 6: []} self.myGame.tableau[1] = [Card(10, 'h'), Card(7, 'c')] self.myGame.tableau[7] = [Card(5, 'c'), Card(1, 'd'), Card(8, 'h')] self.assertTrue(self.myGame.checkLegalTableauMove(1, 1, 7)) self.assertFalse(self.myGame.checkLegalTableauMove(1, 7, 1)) self.assertFalse(self.myGame.checkLegalTableauMove(1, 2, 1)) self.assertFalse(self.myGame.checkLegalTableauMove(1, 1, 2)) self.assertFalse(self.myGame.checkLegalTableauMove(2, 7, 2)) self.assertFalse(self.myGame.checkLegalTableauMove(1, 1, 1)) def testCheckLegalTableauFoundationMove(self): self.myGame.tableau = {2: [], 3: [], 4: [], 5: [], 6: []} self.myGame.tableau[1] = [Card(10, 'h'), Card(7, 'c'), Card(1, 'c')] self.myGame.tableau[2] = [Card(4, 'c')] self.myGame.tableau[7] = [Card(5, 'c'), Card(1, 'd'), Card(8, 'h')] self.myGame.foundation = { 1: [], 2: [Card(6, 'h'), Card(7, 'h')], 3: [], 4: [Card(3, 'c')] } self.assertTrue(self.myGame.checkLegalTableauFoundationMove(2, 4)) self.assertTrue(self.myGame.checkLegalTableauFoundationMove(1, 1)) self.assertFalse(self.myGame.checkLegalTableauFoundationMove(7, 1)) self.assertTrue(self.myGame.checkLegalTableauFoundationMove(2, 4)) def testCheckLegalWasteFoundationMove(self): self.myGame.foundation = { 1: [], 2: [Card(6, 'h'), Card(7, 'h')], 3: [], 4: [Card(3, 'c')] } self.myGame.waste = [] self.assertFalse(self.myGame.checkLegalWasteFoundationMove(1)) self.myGame.waste = [Card(2, 'c'), Card(1, 'h')] self.assertTrue(self.myGame.checkLegalWasteFoundationMove(1)) self.myGame.waste = [Card(2, 'c'), Card(4, 'c')] self.assertTrue(self.myGame.checkLegalWasteFoundationMove(4)) self.assertFalse(self.myGame.checkLegalWasteFoundationMove(3)) def testCheckLegalWasteTableauMove(self): self.myGame.tableau = {2: [], 3: [], 4: [], 5: [], 6: []} self.myGame.tableau[1] = [Card(10, 'h'), Card(7, 'c'), Card(1, 'c')] self.myGame.tableau[2] = [Card(4, 'c')] self.myGame.tableau[7] = [Card(5, 'c'), Card(1, 'd'), Card(8, 'h')] self.myGame.waste = [] self.assertFalse(self.myGame.checkLegalWasteTableauMove(1)) self.myGame.waste = [Card(7, 'c')] self.assertTrue(self.myGame.checkLegalWasteTableauMove(7)) self.assertFalse(self.myGame.checkLegalWasteTableauMove(3)) self.myGame.waste = [Card(2, 'c'), Card(13, 'c')] self.assertTrue(self.myGame.checkLegalWasteTableauMove(3)) def testExecuteMove(self): self.myGame.tableau = {2: [], 3: [], 4: [], 5: [], 6: []} self.myGame.tableau[1] = [Card(10, 'h'), Card(7, 'c'), Card(1, 'c')] self.myGame.waste = [Card(10, 'h'), Card(1, 's')] cardlist = self.myGame.tableau[1] card = cardlist[-1] self.myGame.tableau[2] = [Card(4, 'c')] self.myGame.tableau[7] = [Card(5, 'c'), Card(1, 'd'), Card(8, 'h')] self.myGame.foundation = { 1: [], 2: [Card(6, 'h'), Card(7, 'h')], 3: [], 4: [Card(3, 'c')] } self.myGame.waste = [Card(2, 'c'), Card(7, 'c')] self.myGame.executeMove(1, [1, 1, 2]) self.assertIn(card, self.myGame.tableau[2]) self.assertNotIn(card, self.myGame.tableau[1]) cardlist = self.myGame.tableau[7] card = cardlist[-1] self.myGame.executeMove(2, [7, 1]) self.assertIn(card, self.myGame.foundation[1]) self.assertNotIn(card, self.myGame.tableau[7]) card = self.myGame.waste[-1] self.myGame.executeMove(3, [7]) self.assertIn(card, self.myGame.tableau[7]) self.assertNotIn(card, self.myGame.waste) card = self.myGame.waste[-1] self.myGame.executeMove(4, [4]) self.assertIn(card, self.myGame.foundation[4]) self.assertNotIn(card, self.myGame.waste)