Exemplo n.º 1
0
class Game(object):

    def __init__(self, first='W'):
        super(Game, self).__init__()
        self.white, self.black = Player('W'), Player('B')
        self.players = [self.white, self.black] if first == 'W' else [self.black, self.white]
        self.plansza = Plansza()

    def is_finished(self):
        if sum(self.plansza.count_pawnsWB()) == 64:
            return True
        elif self.players[0].blocked and self.players[1].blocked:
            return True
        else:
            return False

    def get_result(self):
        whites, blacks = self.plansza.count_pawnsWB()
        if whites > blacks:
            return "White won: %d to %d" % (whites, blacks)
        elif blacks > whites:
            return "Blacks won: %d to %d" % (blacks, whites)
        else:
            return "Draw %d to %d" % (blacks, whites)

    def play(self):
#        print self.plansza
        for player in itertools.cycle(self.players):
            self.plansza = player.think_and_move(self.plansza)           
#            if player.blocked:
#                print "\n%s can't move" % player.color
#            else:
#                print '\n' + str(self.plansza)
            if self.is_finished():
                break
Exemplo n.º 2
0
def test_count_pawnsBW():
	tekst = '''	B B B * * * * *
				* * * * * * * *
				* * * * * * * *
				* * * B W * * *
				* * * W B * * *
				* * * * * * * *
				* * * * * * * *
				* * * * * W W W '''	
	plansza = Plansza()
	plansza.load(tekst)
	w, b = plansza.count_pawnsWB()
	assert w==5 and b==5


# class PlanszaTest(unittest.TestCase):

	# def test_znalezione_ruchy(self):
	# 	plansza = Plansza()
	# 	plansza.find_moves('B')
	# 	expected=set([(3, 5), (2, 4), (4, 2), (5, 3)])
	# 	actual = set(plansza.available_moves)
	# 	self.assertEqual(actual, expected)

	# def test_wykonal_ruch(self):
	# 	plansza = Plansza()
	# 	plansza.make_move(3, 5, 'B')

	# 	self.assertEqual(plansza[3,5], 'B')
	# 	self.assertEqual(plansza[3,4], 'B')

	# def test_wykonal_ruch2(self):
	# 	plansza = Plansza()
	# 	plansza.make_move(5, 4, 'W')

	# 	self.assertEqual(plansza[5,4], 'W')
	# 	self.assertEqual(plansza[4,4], 'W')

	# def test_wykonal_ruch3(self):
		
	# 	start = '''		* * * * * W * *
	# 					* * * * * B * *
	# 					* * * * W B * *
	# 					* * * B B B * *
	# 					* * * B W * W B
	# 					* * * B W B W *
	# 					* * * * * W * B
	# 					* * * * * * * * '''
		
	# 	expected = '''	* * * * * W * *
	# 					* * * * * B * *
	# 					* * * * W B * *
	# 					* * * B B B * *
	# 					* * * B B B B B
	# 					* * * B W B B *
	# 					* * * * * W * B
	# 					* * * * * * * *'''

		# plansza = Plansza()
		# plansza.load(start)
		# plansza.make_move(4,5,'B')

		# end=Plansza()
		# end.load(expected)

		# self.assertEqual(plansza, end)

	


#if __name__ == '__main__':
#	unittest.main()


		
		
		
		
Exemplo n.º 3
0
def test_count_pawnsBW_clean():
	plansza = Plansza()
	whites, blacks = plansza.count_pawnsWB()
	assert blacks==2 and whites==2, 'liczba pionów się nie zgadza'