Exemple #1
0
def cpu0(request):
    if request.method == 'POST':
        body = request.body
        data = json.loads(body)
        player = data['player']
        squares = data['squares']

        AI = RandomAI(player, squares)
        new_squares, history = AI.think()

        if (new_squares is not None):
            response = {
                "success": True,
                "squares": new_squares,
                "history": history,
                "isEnd": OthelloSystem.isEnd(new_squares),
            }
        else:
            response = {
                "success": False,
                "isEnd": OthelloSystem.isEnd(squares),
            }
        return JsonResponse(response)
    else:
        return Http404
Exemple #2
0
 def think(self):
     squares = None
     history = None
     # 置く場所があるか判断.なければパスをする.
     for i in range(64):
         temp_squares, temp_history = OthelloSystem.put(self._player, self._squares, i)
         if temp_squares is not None:
             break
         if i == 63:
             return None, None
     # ランダムに置いて最初にヒットしたところを選ぶ
     while (squares is None and history is None):
         idx = random.randrange(64)
         squares, history = OthelloSystem.put(self._player, self._squares, idx)
     return squares, history
Exemple #3
0
 def think(self):
     playerBoard, cpuBoard = BitBoard.squaresToBoard(self._squares)
     legalBoard = BitBoard.makeLegalBoard(cpuBoard, playerBoard)
     legalIndices = BitBoard.getIndices(legalBoard)
     maxScore = -999
     putPos = -1
     for idx in legalIndices:
         temp_cpuBoard, temp_playerBoard, reverseBoard = BitBoard.reverse(cpuBoard, playerBoard, idx)
         temp_score = Evaluator.evaluate(0, temp_cpuBoard, temp_playerBoard)
         print(temp_score)
         if temp_score > maxScore:
             maxScore = temp_score
             putPos = idx
     return OthelloSystem.put(self._player, self._squares, putPos)
Exemple #4
0
def putStone(request):
    if request.method == 'POST':
        body = request.body
        data = json.loads(body)
        player = data['player']
        squares = data['squares']
        put_pos = data['put_pos']

        new_squares, history = OthelloSystem.put(player, squares, put_pos)

        if (new_squares is not None):
            response = {
                "success": True,
                "squares": new_squares,
                "history": history,
            }
        else:
            response = {
                "success": False,
            }
        return JsonResponse(response)
    else:
        return Http404
Exemple #5
0
def putStone(request):
    if request.method == 'POST':
        body = request.body
        data = json.loads(body)
        player = data['player']
        squares = data['squares']
        put_pos = data['put_pos']

        playerBoard, cpuBoard = BitBoard.squaresToBoard(squares)

        #-------------------------------D-----------------
        if Kifu.objects.filter(taikyoku_id=Taikyoku(id=1)).count() % 2 == 1:
            kifu = Kifu(
                taikyoku=Taikyoku(id=1),
                player=Taikyoku.objects.get(id=1).player_black_id,
                count=Kifu.objects.filter(taikyoku_id=Taikyoku(id=1)).count() +
                1,
                position=put_pos,
                board_black=playerBoard,
                board_white=cpuBoard)
        else:
            kifu = Kifu(
                taikyoku=Taikyoku(id=1),
                player=Taikyoku.objects.get(id=1).player_white_id,
                count=Kifu.objects.filter(taikyoku_id=Taikyoku(id=1)).count() +
                1,
                position=put_pos,
                board_black=playerBoard,
                board_white=cpuBoard)
        kifu.save()

        #--------------deka----------------------

        new_squares, history = OthelloSystem.put(player, squares, put_pos)

        if (new_squares is not None):
            response = {
                "success": True,
                "squares": new_squares,
                "history": history,
                "isEnd": OthelloSystem.isEnd(new_squares)
            }
        else:
            response = {
                "success": False,
            }
        return JsonResponse(response)
    else:
        return Http404
#---------------------D-------------------------------------------
    if request.method == 'GET':

        player_id = request.GET.get('player_id')
        taikyoku_id = request.GET.get('taikyoku_id')

        kifu = Kifu.objects.get(taikyoku=taikyoku_id).latest()
        squares = BitBoard.boardToSquares(kifu.board_black, kifu.board_white)
        response = {
            "player": kifu.player,
            "squares": squares,
        }

        return JsonResponse(response)
        # return JsonResponse(response)
    else:
        return Http404
Exemple #6
0
 def think(self):
     playerBoard, cpuBoard = BitBoard.squaresToBoard(self._squares)
     putPos = DeepEvalAI.deepThink(DeepEvalAI.DEPTH, playerBoard, cpuBoard, True)
     return OthelloSystem.put(self._player, self._squares, putPos)