Пример #1
0
def play_game(state_list, action_list, Qtable):

	step = 0 # 合計ループ数
	old_state = new_state = [] #- state
	flag = 0
	reset()
	pt.init(0.5)

	# メインループ
	while(pt.alive()):

		#########################
		# ループごとの解析、操作をここに書く

		if step % 180 == 0 and flag == 0:
			new_board = pt.getBoard()
			for i in range(len(new_board)):
				for j in range(len(new_board[i])):
					if new_board[i][j] > 0 and new_board[i][j] < 8:	new_board[i][j] = 1
			piece = pt.getPiece()
			new_state = [new_board, piece]

		if new_state != old_state and flag == 0:
			action, value = egreedy.search_action(new_state)
			if action == []:
				action = egreedy.eGreedy(new_state)
			old_state = new_state
			flag = 1

		if step % 10 == 0 and flag == 1:
			flag = doaction(action, piece)
			if step % 100 == 0:	flag = 2

#			print(new_state)

		#########################
	
		# 次のループへ
		pt.loop()
		if flag == 2:
			print pt.param.flag['update']
			pt.move('down')
			if pt.param.flag['update']:
				print "update"
				pt.loop()
				flag = 0
			if pt.param.flag['gameover']:	alive = flag = 0
		step += 1

	# 終了    
	pt.quit()
Пример #2
0
       [8,0,0,0,0,0,0,0,0,0,0,8],
       [8,0,0,0,0,0,0,0,0,0,0,8],
       [8,0,0,0,0,0,0,0,0,0,0,8],
       [8,0,0,0,0,0,0,0,0,0,0,8],
       [8,8,8,8,8,8,8,8,8,8,8,8],
       [8,8,8,8,8,8,8,8,8,8,8,8],
       [8,8,8,8,8,8,8,8,8,8,8,8],
       [8,8,8,8,8,8,8,8,8,8,8,8],
       [8,8,8,8,8,8,8,8,8,8,8,8],
       [8,8,8,8,8,8,8,8,8,8,8,8]]


# メインループ
while(pt.alive()):

    #########################
    # ループごとの解析、操作をここに書く
#    if step%120==0:
#        ans = pt.answer(m,[[1,1,1],[1,0,0],[1,0,0]], 8, -4, 2)
#        pprint(ans)
       
    #########################

    # 次のループへ
    pt.loop()
    step += 1

# 終了    
pt.quit()