import keras
import numpy as np
from os.path import abspath, dirname

import sys

import os

from src.play.model.Move import Move


class SimplestNNBot:

    def __init__(self):
        project_dir = dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))
        # try to make this path relative instead of absolute to project_dir,
        # otherwise it might make troubles when packing it into an executable TODO
        filepath = os.path.join(project_dir, 'src\learn\simplest_move_prediction\model.h5')
        self.model = keras.models.load_model(filepath)

    def genmove(self, color, game) -> Move:
        # We're still interested in the playable locations
        playable_locations = game.get_playable_locations(color)

        # Format the board and make predictions
        board = game.board.tolist()
        board = np.array([[entry for row in board for entry in row]])
        pred_moves = self.model.predict(board)
        # print(pred_moves)

        pred_moves = pred_moves.reshape(9, 9)
        # print(pred_moves)
        # print(playable_locations)
        dummy_value = -10 if color == 'b' else 10
        potential_moves = np.array([[dummy_value]*9]*9, dtype=float)
        for move in playable_locations:
            # print(move)
            if move.is_pass:
                continue
            loc = move.to_matrix_location()
            # print(loc)
            potential_moves[loc[0]][loc[1]] = pred_moves[loc[0]][loc[1]]
        # print([i for row in potential_moves for i in row])
        # print(self.color)
        if color == 'b':
            row, col = np.unravel_index(
                potential_moves.argmax(),
                potential_moves.shape)
        elif color == 'w':
            row, col = np.unravel_index(
                potential_moves.argmin(),
                potential_moves.shape)
        # random_choice = rn.choice(playable_locations)
        move = Move(col=col, row=row)

        if potential_moves[move.to_matrix_location()] == dummy_value:
            move = Move(is_pass=True)

        return move

@@ -61,16 +61,106 @@
  dirname
+%0Afrom src.play.model.Move import Move%0Afrom src.play.model.Board import WHITE, BLACK, EMPTY
 %0A%0Aimport
@@ -323,16 +323,29 @@
 dirname(
+%0A            
 abspath(
@@ -499,16 +499,26 @@
  it into
+%0A        #
  an exec
@@ -561,16 +561,29 @@
 th.join(
+%0A            
 project_
@@ -702,43 +702,598 @@
 def 
-genmove(self, color, game) -%3E Move:
+board_to_input(self):%0A        b = self.game.board%0A        if self.color == 'b':%0A            me = BLACK%0A            other = WHITE%0A        else:%0A            me = WHITE%0A            other = BLACK%0A        my_board = (b == me) * 2 - 1%0A        other_board = (b == other) * 2 - 1%0A%0A        my_board_vect = my_board.reshape(%0A            1, my_board.shape%5B0%5D*my_board.shape%5B1%5D)%0A        other_board_vect = other_board.reshape(%0A            1, other_board.shape%5B0%5D*other_board.shape%5B1%5D)%0A        return np.append(my_board_vect, other_board_vect)%0A%0A    def genmove(self):%0A        print('NN generating move')
 %0A   
@@ -1377,16 +1377,21 @@
 tions = 
+self.
 game.get
@@ -1410,16 +1410,21 @@
 cations(
+self.
 color)%0A%0A
@@ -1483,104 +1483,34 @@
     
-board = game
+inp = self
 .board
-.tolist()%0A        board = np.array(%5B%5Bentry for row in board for entry in row%5D%5D
+_to_input(
 )%0A  
@@ -1547,21 +1547,19 @@
 predict(
-board
+inp
 )%0A      
@@ -1716,24 +1716,29 @@
 ue = -10 if 
+self.
 color == 'b'
@@ -2177,16 +2177,21 @@
      if 
+self.
 color ==
@@ -2331,16 +2331,21 @@
    elif 
+self.
 color ==

Update on the NN! WIP, this commit is mostly because I want to pull