seigot/tetris

level1でブロックを順番に置くためのサンプルコード

Opened this issue · 1 comments

level1でブロックを順番に置くためのサンプルコード
大変だが180ブロック分全て固定で置く根気があれば完成するはず。

#!/usr/bin/python3
# -*- coding: utf-8 -*-

from datetime import datetime
import pprint
import random

class Block_Controller(object):

    # init parameter
    board_backboard = 0
    board_data_width = 0
    board_data_height = 0
    ShapeNone_index = 0
    CurrentShape_class = 0
    NextShape_class = 0

    # GetNextMove is main function.
    # input
    #    GameStatus : this data include all field status, 
    #                 in detail see the internal GameStatus data.
    # output
    #    nextMove : this data include next shape position and the other,
    #               if return None, do nothing to nextMove.
    def GetNextMove(self, nextMove, GameStatus):

        t1 = datetime.now()

        # print GameStatus
        print("=================================================>")
        pprint.pprint(GameStatus, width = 61, compact = True)

        # ブロックを何回回転させるか、x座標を定義する
        block_location_list = [
            # [direction, x]
            [1,1], # 1
            [3,5], # 2
            [0,8], # 3
            [3,4], # 4
            [0,0], # 5
            [1,6], # 6
            [1,2], # 7
            [0,9], # 8
            # [0,0], # N
        ]

        # print GameStatus
        print("=================================================>")
        pprint.pprint(GameStatus, width = 61, compact = True)

        # search best nextMove -->
        current_block_No = GameStatus["judge_info"]["block_index"] - 1
        if current_block_No < len(block_location_list):
                # my_code
                nextMove["strategy"]["direction"] = block_location_list[current_block_No][0]
                nextMove["strategy"]["x"] = block_location_list[current_block_No][1]
                nextMove["strategy"]["y_operation"] = 1
                nextMove["strategy"]["y_moveblocknum"] = 1
        else:
                # random sample
                nextMove["strategy"]["direction"] = 0
                nextMove["strategy"]["x"] = 0
                nextMove["strategy"]["y_operation"] = 1
                nextMove["strategy"]["y_moveblocknum"] = 1
        # search best nextMove <--

        # return nextMove
        print("===", datetime.now() - t1)
        print(nextMove)
        return nextMove

BLOCK_CONTROLLER = Block_Controller()

Hey, I'm a bit lost here! Not sure which file I should be fixing. Could you give me a bit more to go on? Maybe add some details to the issue or drop a comment with some extra hints? Thanks!

Have feedback or need help?
Feel free to email info@gitauto.ai.