Example #1
0
def startgame(board, has_computer):
	rounds = 0
	board.draw()
	if (has_computer):
		computer = game.computer(board)
	while (1):
		rounds += 1
		print 'Round: ' + str(rounds)
		for i in range(0,len(players)):
			player = players[i]
			symbol = player_symbols[i]
			if player == 'Computer':
				print "computer plays: " + symbol
				computer.play(symbol)
			else:        
				print player + " make your move (enter column number!)"
				while (1):
					try:
						play = raw_input(prompt)
						if not board.play(symbol, int(play)):
							raise Exception("Invalid play")
						break
					except Exception as e:
						print e
						print "Oops! Please try again, " + player
			board.draw()
			if (board.fourinarow is not None):
				# SOMEONE HAS SOMETHING IN A ROW!
				if (board.fourinarow == symbol):
					print "WOO HOO! CONGRATULATIONS " + player + " YOU WON, IN " + str(rounds) + " ROUNDS !"
					return
Example #2
0
	def new_game(self, event):      # --- teiknar mynd af nyju bordi yfir gamla, gamla sést ef stærd breytist.
		print "Stofna nýjan leik!"
		afbrigdi = self.afbrigdi.GetValue()
		staerd = self.boardSize()
		assert(staerd != False)
 		print self.Against()
		ntowin = self.ntowin()
		assert(ntowin > 0)
		print "ntowin=" + str(ntowin)
		if self.Against() == 'Mennskur':        # --- ekki alveg klár á hvort þetta sé besta leiðin | ses: jamm, þetta er ekki fallegt en sleppur :-)
                        self.board = game.board(self.size.GetValue(), ntowin) 
                        self.gboard = wxgame.GraphicalBoard(self, self.board, 2) # XXX: hardcoding 2 players !
                        self.panel = self.gboard
                        self.IN_GAME = True
                if self.Against() == u'Tölva': # XXX: Erfiðleikastig?
			difficulty = self.Difficulty()
			assert(difficulty > 0)
			self.HAS_COMPUTER = True
                        self.board = game.board(self.size.GetValue(), ntowin) 
                        self.gboard = wxgame.GraphicalBoard(self, self.board, 2) # XXX: hardcoding 2 players !
			self.gboard.computer = True
			self.gboard.computer_cb = self.Computer
			self.computer = game.computer(self.board, difficulty) # XXX: hardcoded difficulty = 3 (same as in constructor of game.computer)
                        self.IN_GAME = True

		self.update_nextplayer(1) # spilari 1 á að gera í upphafi !
		self.gboard.game_mode = self.afbrigdi_to_gm(afbrigdi)
Example #3
0
 def test_computer(self):
     assert computer() in ['R', 'P', 'S', 'L', 'V']
Example #4
0
def symbol_to_n(symbol):
	n = 0
	for symbol in symbols:
		if symbol == symbols[n]:
			return n
		n += 1

	return -1

(height, width) = [int(val) for val in size.split("x")]

for r in range(0,rounds):
	game_over = 0
	board = game.board(size, 3) # 3-in-a-row !
	computer = game.computer(board,difficulty)
	if (r % 10 == 0):
		print "Round %d/%d"%(r+1,rounds)
	computer_player = random.randrange(2) # which player is the computer?
	while (not game_over):
		#board.draw()
		#print "Computer should play: " + str(symbols[computer_player])
		# we are the random dude?
		for player in [0, 1]:
			if (board.fourinarow is not None or board.freespaces == 0):
				#print "Player %s is playing, but the game is over, or no free spaces"%player
				break
			if player == computer_player:
				computer.play(symbols[player])
			else:
				while (board.play(symbols[player], random.randrange(width)) != True):