示例#1
0
 def test_black_pawn_attack(self):
     b = Board("rnbqkbnr", #8
               "p.pppppp", #7
               ".p......", #6
               "P.P.....", #5
               "........", #4
               "........", #3
               ".P.PPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('b6')
     self.assertEqual(moves, {'a5', 'b5', 'c5'})
示例#2
0
 def test_black_pawn_attack_starting(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "PPP.....", #6
               "........", #5
               "........", #4
               "........", #3
               "...PPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('b7')
     self.assertEqual(moves, {'a6', 'c6'})
示例#3
0
 def test_white_pawn_attack_starting(self):
     b = Board("rnbqkbnr", #8
               "...ppppp", #7
               "........", #6
               "........", #5
               "........", #4
               "ppp.....", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('b2')
     self.assertEqual(moves, {'a3', 'c3'})
示例#4
0
 def test_white_rook_attack(self):
     b = Board("rnbqkbnr", #8
               "p.pp..pp", #7
               "........", #6
               ".p.R.p..", #5
               "P.......", #4
               "...b....", #3
               ".PPPPPPP", #2
               ".NBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('d5')
     self.assertEqual(moves, {'b5', 'c5', 'd3', 'd4', 'd6', 'd7', 'e5', 'f5'})
示例#5
0
 def test_white_pawn_attack(self):
     b = Board("rnbqkbnr", #8
               ".p.ppppp", #7
               "........", #6
               "........", #5
               "p.p.....", #4
               ".P......", #3
               "P.PPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('b3')
     self.assertEqual(moves, {'a4', 'b4', 'c4'})
示例#6
0
 def test_white_bishop_attack(self):
     b = Board("rnbqkbnr", #8
               ".ppp.ppp", #7
               "........", #6
               "........", #5
               ".p......", #4
               "BP......", #3
               "PbPPPPPP", #2
               "RN.QKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a3')
     self.assertEqual(moves, {'b2', 'b4'})
示例#7
0
 def test_white_bishop(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "........", #4
               "BP......", #3
               "P.PPPPPP", #2
               "RN.QKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a3')
     self.assertEqual(moves, {'b2', 'b4', 'c1', 'c5', 'd6', 'e7'})
示例#8
0
 def test_black_knight_attack(self):
     b = Board("r.bqkbnr", #8
               "pppppppp", #7
               "..n.....", #6
               "P...P...", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('c6')
     self.assertEqual(moves, {'a5', 'b4', 'b8', 'd4', 'e5'})
示例#9
0
 def test_black_knight_start(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('b8')
     self.assertEqual(moves, {'a6', 'c6'})
示例#10
0
 def test_black_bishop_attack(self):
     b = Board("rn.qkbnr", #8
               "pBpppppp", #7
               "bp......", #6
               ".P......", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a6')
     self.assertEqual(moves, {'b5', 'b7'})
示例#11
0
 def test_white_king_in_check(self):
     b = Board(".nbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "r...K...", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQ.BNR", #1
               #abcdefgh
               )
     moves = b.in_check(White)
     self.assertEqual(moves, True)
示例#12
0
 def test_king_that_cannot_move(self):
    b = Board("rnbqkbnr", #8
              "pppppppp", #7
              "........", #6
              "........", #5
              "........", #4
              "........", #3
              "PPPPPPPP", #2
              "RNBQKBNR", #1
              #abcdefgh
              )
    moves = b.valid_moves('e1')
    self.assertEqual(moves, set())
示例#13
0
 def test_black_queen_start(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('d8')
     self.assertEqual(moves, set())
示例#14
0
 def test_black_king_in_check(self):
     b = Board("rnbq.bnr", #8
               "pppppppp", #7
               "........", #6
               "R..k....", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               ".NBQKBNR", #1
               #abcdefgh
               )
     moves = b.in_check(Black)
     self.assertEqual(moves, True)
示例#15
0
 def test_white_knight_attack(self):
     b = Board("rnbqkbnr", #8
               ".ppp.ppp", #7
               "........", #6
               "........", #5
               "p...p...", #4
               "..N.....", #3
               "PPPPPPPP", #2
               "R.BQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('c3')
     self.assertEqual(moves, {'a4', 'b1', 'b5', 'd5', 'e4'})
示例#16
0
 def test_white_king_not_in_check(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "R.......", #5
               "........", #4
               "........", #3       
               "PPPPPPPP", #2
               ".NBQKBNR", #1
               #abcdefgh
               )
     moves = b.in_check(White)
     self.assertEqual(moves, False)
示例#17
0
 def test_white_pawn_starting(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('e2')
     self.assertEqual(moves, {'e3', 'e4'})
示例#18
0
 def test_white_rook_start(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a1')
     self.assertEqual(moves, set())
示例#19
0
 def test_black_rook(self):
     b = Board(".nbqkbnr", #8
               ".ppppppp", #7
               "r.......", #6
               "........", #5
               "p.......", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a6')
     self.assertEqual(moves, {'a5', 'a7', 'a8', 'b6', 'c6',
                              'd6', 'e6', 'f6', 'g6', 'h6'})
示例#20
0
 def test_king_taking_a_piece(self):
     b = Board("rnbqkbnr", #8
              "pppppppp", #7
              "....K...", #6
              "........", #5
              "........", #4
              "........", #3
              "PPPPPPPP", #2
              "RNBQ.BNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('e6')
     self.assertEqual(moves, {'d5', 'd6', 'd7', 'e5',
                             'e7', 'f5', 'f6', 'f7'})
示例#21
0
 def test_black_rook_attack(self):
     b = Board(".nbqkbnr", #8
               ".ppppppp", #7
               "........", #6
               "pP.r.P..", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('d5')
     self.assertEqual(moves, {'b5', 'c5', 'd2', 'd3',
                              'd4', 'd6', 'e5', 'f5'})
示例#22
0
 def test_white_rook(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "P.......", #5
               "........", #4
               "R.......", #3
               ".PPPPPPP", #2
               ".NBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a3')
     self.assertEqual(moves, {'a1', 'a2', 'a4', 'b3', 'c3',
                              'd3', 'e3', 'f3', 'g3', 'h3'})
示例#23
0
 def test_black_queen(self):
     b = Board("rnb.kbnr", #8
               "pp.ppppp", #7
               "........", #6
               "q.p.....", #5
               "........", #4
               "........", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('a5')
     self.assertEqual(moves, {'a2', 'a3', 'a4', 'a6', 'b4',
                              'b5', 'b6', 'c3', 'c7', 'd2',
                              'd8'})
示例#24
0
 def test_white_queen_attack(self):
     b = Board("r..qk.nr", #8
               "p.....pp", #7
               "..npb...", #6
               ".p.Q.p..", #5
               "..p.p...", #4
               "...b....", #3
               "PPPPPPPP", #2
               "RNBQKBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('d5')
     self.assertEqual(moves, {'b5', 'c4', 'c5', 'c6', 'd3',
                              'd4', 'd6', 'e4', 'e5', 'e6',
                              'f5'})
示例#25
0
 def test_white_queen(self):
     b = Board("rnbqkbnr", #8
               "pppppppp", #7
               "........", #6
               "........", #5
               "....P.Q.", #4
               "........", #3
               "PPPP.PPP", #2
               "RNB.KBNR", #1
               #abcdefgh
               )
     moves = b.valid_moves('g4')
     self.assertEqual(moves, {'d1', 'd7', 'e2', 'e6', 'f3',
                              'f4', 'f5', 'g3', 'g5', 'g6',
                              'g7', 'h3', 'h4', 'h5'})
示例#26
0
 def test_move(self):
     b = Board("rnbqkbnr", #8
              "pppppppp", #7
              "........", #6
              "........", #5
              "........", #4
              "........", #3
              "PPPPPPPP", #2
              "RNBQKBNR", #1
              #abcdefgh
              )
     move = b.move('a2','a3')
     moved_b = Board("rnbqkbnr", #8
              "pppppppp", #7
              "........", #6
              "........", #5
              "........", #4
              "P.......", #3
              ".PPPPPPP", #2
              "RNBQKBNR", #1
              #abcdefgh
              )
     comparison = move.__eq__(moved_b)
     self.assertEqual(comparison, True)
示例#27
0
文件: glyphs.py 项目: nuiie/tui-tanu
def detect_glyph(image, hBox, vBox, game):
	
	augmented = Augmented()
	board = Board(image)
	board.start(size = 4)
	if board.hasTui():
		tuis = board.getTuis(getClassifier())
		board.causalBoard, causalTuis = feedCausal(board, tuis, hBox, vBox)
		causalOutput(board, causalTuis)
		game.setArea(board.causalBoard)
		display(board)
		
		cv2.namedWindow('score', cv2.WINDOW_NORMAL)
		cv2.imshow('score', game.getScoreBoard())
		if cv2.waitKey(1) & 0xFF == ord(' '):  # end subround
			game.endSubRound(causalTuis[:])
		return augmented.start(board, causalTuis)
	else:
		display(board)
		if cv2.waitKey(1) & 0xFF == ord(' '):  # end subround
			self.game.endSubRound(causalTuis[:])
		return []
示例#28
0
文件: main.py 项目: nuiie/tui-tanu
def main():
	#camera setup
	cap = cv2.VideoCapture(0)
	print 'Video resolution: '+' x '.join(set_res(cap,1280,720))
	tuis = []
	hBox = causalBox(winSize = 10)
	vBox = causalBox(winSize = 10)
	ret = True
	clf = getClassifier()
	plyerName = ["John","Doe","Tommy","Emmanuel"]
	game = GameCtrler(plyerName)
	causalTuis = None
	while ret:
		now = time.time() # get the time
		ret, rawImg = cap.read()
		if ret is False:
			print "Error aquring image"
			break
		board = Board(rawImg)
		board.getA4(size = 4)
		board.getCircle()
		
		# setup causal Box
		lenNeighbor = np.round(board.size*210/14)
		vBox.setThresh(lenNeighbor)
		hBox.setThresh(lenNeighbor)
		
		# check if circles in A4
		if board.horizontalCircles is not None or board.verticalCircles is not None:
			board.drawCircles()
			tuis = board.getTuis()
			
			hTuiTmp = []
			vTuiTmp = []
			for tui in tuis: # latter + name
				tui.getLetter()
				if tui.letter.size == 0:
					print 'letter size 0'
				else:
					letterPercentage = float(np.count_nonzero(tui.letter))/tui.letter.size*100.0
					if  letterPercentage > 3.9: # if letter area is more than 3.9% of img
						tui.getHuMoment()
						tui.getTuiName(clf)
				# split h and v tuis for feed in causalbox
				if tui.position[0] == 'h':
					hTuiTmp.append((tui.position[1],tui.name))
				elif tui.position[0] == 'v':
					vTuiTmp.append((tui.position[1],tui.name))
				else: print "invalid h/v tui position"		
			
		
			hBox.feedIn(hTuiTmp) # feed causalbox
			vBox.feedIn(vTuiTmp)
			
			# choose v or h
			causalBoard = board.vertical.copy() if len(vBox.tuis) > len(hBox.tuis) else board.horizontal.copy()
			causalTuis = vBox.tuis[:] if len(vBox.tuis) > len(hBox.tuis) else hBox.tuis[:]
			
			game.setArea(causalBoard) #set player area			
			
			for i in causalTuis:
				cv2.circle(causalBoard ,i.position,np.round(board.size*210/14),(0,255,0),2) # draw the outer circle
				cv2.circle(causalBoard ,i.position,2,(0,0,255),3) # draw the center of the circle
				if i.isLegit:
					cv2.putText(causalBoard, i.getVotedName(), i.position, cv2.FONT_HERSHEY_SIMPLEX, 1,(255,0,0),4) # write name on img
			cv2.namedWindow('a', cv2.WINDOW_NORMAL)
			cv2.imshow('a',causalBoard)
			
			cv2.namedWindow('score', cv2.WINDOW_NORMAL)
			cv2.imshow('score',game.getScoreBoard())
			
		else:
			print 'No circle in both hor and ver a4'
				
		# display
		cv2.namedWindow('thresh', cv2.WINDOW_NORMAL)
		cv2.imshow('thresh',board.thresh)
		cv2.namedWindow('boardDetect', cv2.WINDOW_NORMAL)
		cv2.imshow('boardDetect',board.boardDetect)
	
		# condition for exit
		# if len(tuis) > 0:
			# ret = stop(cv2.waitKey(1), tuis)
		# else:
			# ret = stop(cv2.waitKey(1))
		
		if causalTuis is None:
			ret = playerDebug(cv2.waitKey(1), game)
		else:
			ret = playerDebug(cv2.waitKey(1), game, causalTuis)
			
		# time controller
		elapsed = time.time() - now  # how long was it running?
		if elapsed < 0.2:
			time.sleep(0.2-elapsed)       # sleep accordingly so the full iteration takes 1 second
		elapsed = time.time() - now  # how long was it running?
		# print str(elapsed)+":",
	
	cv2.destroyAllWindows()
		
	
	return 0