#!/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()
        my_list = [
            [1,1,0,9,1,1],
            [2,2,0,4,1,1],
            [3,3,0,8,1,1],
            [4,4,1,6,1,1],
            [5,5,0,2,1,1],
            [6,6,0,7,1,1],
            [7,7,1,3,1,1],
            [8,1,0,1,1,2],
            [9,2,2,2,1,2],
            [10,3,1,8,1,2],
            [11,4,0,5,1,2],
            [12,5,0,8,1,2],
            [13,6,1,5,1,2],
            [14,7,1,3,1,2],
            [15,1,0,0,1,3],
            [16,2,1,8,1,3],
            [17,3,2,6,1,3],
            [18,4,0,3,1,3],
            [19,5,0,1,1,3],
            [20,6,1,4,1,3],
            [21,7,0,8,1,3],
            [22,1,0,1,1,4],
            [23,2,0,5,1,4],
            [24,3,2,2,1,4],
            [25,4,2,9,1,4],
            [26,5,0,3,1,4],
            [27,6,1,1,1,4],
            [28,7,1,8,1,4],
            [29,1,0,0,1,5],
            [30,2,0,6,1,5],
            [31,3,2,7,1,5],
            [32,4,0,5,1,5],
            [33,5,0,3,1,5],
            [34,6,1,1,1,5],
            [35,7,0,6,1,5],
            [36,1,0,0,1,6],
            [37,2,3,3,1,6],
            [38,3,0,9,1,6],
            [39,4,0,3,1,6],
            [40,5,0,1,1,6],
            [41,6,1,4,1,6],
            [42,7,0,7,1,6],
            [43,1,0,0,1,7],
            [44,2,0,1,1,7],
            [45,3,3,7,1,7],
            [46,4,2,9,1,7],
            [47,5,0,5,1,7],
            [48,6,0,3,1,7],
            [49,7,1,7,1,7],
            [50,1,0,9,1,8],
            [51,2,1,3,1,8],
            [52,3,1,6,1,8],
            [53,4,3,7,1,8],
            [54,5,0,3,1,8],
            [55,6,0,6,1,8],
            [56,7,1,1,1,8],
            [57,1,0,0,1,9],
            [58,2,1,2,1,9],
            [59,3,2,8,1,9],
            [60,4,3,2,1,9],
            [61,5,0,4,1,9],
            [62,6,0,7,1,9],
            [63,7,1,1,1,9],
            [64,1,0,0,1,10],
            [65,2,3,4,1,10],
            [66,3,3,8,1,10],
            [67,4,3,8,1,10],
            [68,5,0,3,1,10],
            [69,6,1,4,1,10],
            [70,7,1,1,1,10],
            [71,1,0,6,1,11],
            [72,2,2,3,1,11],
            [73,3,3,6,1,11],
            [74,4,2,9,1,11],
            [75,5,0,5,1,11],
            [76,6,0,8,1,11],
            [77,7,1,7,1,11],
            [78,1,0,0,1,12],
            [79,2,2,9,1,12],
            [80,3,2,1,1,12],
            [81,4,2,4,1,12],
            [82,5,0,1,1,12],
            [83,6,0,6,1,12],
            [84,7,1,3,1,12],
            [85,1,0,0,1,13],
            [86,2,1,6,1,13],
            [87,3,1,2,1,13],
            [88,4,3,6,1,13],
            [89,5,0,8,1,13],
            [90,6,0,4,1,13],
            [91,7,1,2,1,13],
            [92,1,0,0,1,14],
            [93,2,1,8,1,14],
            [94,3,1,5,1,14],
            [95,4,0,1,1,14],
            [96,5,0,6,1,14],
            [97,6,1,1,1,14],
            [98,7,1,3,1,14],
            [99,1,0,9,1,15],
            [100,2,2,8,1,15],
            [101,3,2,5,1,15],
            [102,4,3,7,1,15],
            [103,5,0,2,1,15],
            [104,6,0,5,1,15],
            [105,7,1,1,1,15],
            [106,1,0,0,1,16],
            [107,2,0,3,1,16],
            [108,3,1,5,1,16],
            [109,4,2,5,1,16],
            [110,5,0,8,1,16],
            [111,6,1,6,1,16],
            [112,7,1,1,1,16],
            [113,1,0,0,1,17],
            [114,2,0,8,1,17],
            [115,3,2,7,1,17],
            [116,4,0,1,1,17],
            [117,5,0,7,1,17],
            [118,6,1,5,1,17],
            [119,7,1,3,1,17],
            [120,1,0,9,1,18],
            [121,2,0,2,1,18],
            [122,3,2,1,1,18],
            [123,4,2,6,1,18],
            [124,5,0,3,1,18],
            [125,6,0,5,1,18],
            [126,7,1,3,1,18],
            [127,1,0,0,1,19],
            [128,2,0,1,1,19],
            [129,3,3,8,1,19],
            [130,4,2,7,1,19],
            [131,5,0,8,1,19],
            [132,6,0,3,1,19],
            [133,7,1,5,1,19],
            [134,1,0,0,1,20],
            [135,2,1,3,1,20],
            [136,3,0,9,1,20],
            [137,4,0,5,1,20],
            [138,5,0,7,1,20],
            [139,6,1,5,1,20],
            [140,7,1,1,1,20],
            [141,1,0,4,1,21],
            [142,2,2,3,1,21],
            [143,3,2,1,1,21],
            [144,4,3,8,1,21],
            [145,5,0,1,1,21],
            [146,6,1,6,1,21],
            [147,7,1,3,1,21],
            [148,1,0,0,1,22],
            [149,2,2,5,1,22],
            [150,3,3,2,1,22],
            [151,4,2,9,1,22],
            [152,5,0,7,1,22],
            [153,6,1,8,1,22],
            [154,7,1,6,1,22],
            [155,1,0,0,1,23],
            [156,2,3,3,1,23],
            [157,3,3,8,1,23],
            [158,4,0,1,1,23],
            [159,5,0,5,1,23],
            [160,6,1,2,1,23],
            [161,7,0,4,1,23],
            [162,1,0,0,1,24],
            [163,2,1,2,1,24],
            [164,3,1,8,1,24],
            [165,4,2,6,1,24],
            [166,5,0,8,1,24],
            [167,6,0,5,1,24],
            [168,7,1,7,1,24],
            [169,1,1,3,1,25],
            [170,2,2,9,1,25],
            [171,3,1,2,1,25],
            [172,4,3,5,1,25],
            [173,5,0,2,1,25],
            [174,6,1,6,1,25],
            [175,7,1,4,1,25],
            [176,1,0,0,1,26],
            [177,2,3,8,1,26],
            [178,3,2,0,1,26],
            [179,4,3,7,1,26],
            [180,5,0,3,1,26],
        ]

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

        # search best nextMove -->
        bi = GameStatus["judge_info"]["block_index"] - 1
        if bi < len(my_list):
                # my_code
                nextMove["strategy"]["direction"] = my_list[bi][2]
                nextMove["strategy"]["x"] = my_list[bi][3]
                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,
              "block_index : ", GameStatus["judge_info"]["block_index"],
#              "direction : ", my_list[GameStatus["judge_info"]["block_index"][2]],
#              "x : ", my_list[GameStatus["judge_info"]["block_index"][3]],
#              "y_operation : 1",
#              "y_moveblocknum : 1",
              "/")
        print(nextMove)
        return nextMove

BLOCK_CONTROLLER = Block_Controller()
