Skip to content

Commit

Permalink
debug branch
Browse files Browse the repository at this point in the history
  • Loading branch information
leondelee committed Sep 5, 2018
1 parent 83d503c commit 2f5f42a
Showing 1 changed file with 4 additions and 62 deletions.
66 changes: 4 additions & 62 deletions core/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@

from core import rule
from core.player import Player
from core.predictor import Predictor
from tensorpack import *
from core.DQNModel import Model
from handlers.protocol import Protocol as Pt
import numpy as np
from core.extra.card import Card

logger = logging.getLogger('ddz')

Expand All @@ -21,12 +16,6 @@ def __init__(self, uid: int, username: str, player: Player):
from handlers.loopback import LoopBackSocketHandler
super().__init__(uid, username, LoopBackSocketHandler(self))
self.room = player.room
self.predictor = Predictor(OfflinePredictor(PredictConfig(
model=Model(),
session_init=SaverRestore('C:/Users/44762/PycharmProjects/doudizhu-tornado/core/res/model-92500'),
input_names=['state', 'comb_mask', 'fine_mask'],
output_names=['Qvalue']
)))

def to_server(self, message):
packet = json.dumps(message)
Expand Down Expand Up @@ -74,58 +63,11 @@ def auto_call_score(self, score=0):

def auto_shot_poker(self):
pokers = []
if not self.table.last_shot_poker or self.table.last_shot_seat == self.seat:
pokers.append(self.hand_pokers[0])
else:
pokers = rule.cards_above(self.hand_pokers, self.table.last_shot_poker)

def to_char(pokers):
cards = rule._to_cards(pokers)
for i, card in enumerate(cards):
if card == 'w':
cards[i] = '*'
elif card == 'W':
cards[i] = '$'
elif card == '0':
cards[i] = '10'
return cards
handcards_char = to_char(self.hand_pokers)
last_cards_char = to_char(self.table.last_shot_poker)
print(handcards_char)
print(last_cards_char)
if self.table.last_shot_seat == self.seat:
last_cards_char = []

total_cards = np.ones([60])
total_cards[53:56] = 0
total_cards[57:60] = 0
remain_cards = total_cards - Card.char2onehot60(handcards_char +
to_char(self.table.history[self.seat] +
self.table.history[(self.seat + 1) % 3] +
self.table.history[(self.seat + 2) % 3]))
next_cnt = len(self.table.players[(self.seat + 1) % 3].hand_pokers)
next_next_cnt = len(self.table.players[(self.seat + 2) % 3].hand_pokers)
next_state = remain_cards * (next_cnt / (next_cnt + next_next_cnt))
next_next_state = remain_cards * (next_next_cnt / (next_cnt + next_next_cnt))
prob_state = np.concatenate([next_state, next_next_state])
assert np.all(prob_state < 1.) and np.all(prob_state >= 0.)
# print(self.table.last_shot_poker)
# print(self.hand_pokers)
# print(self.table.players[self.seat].hand_pokers)
intention = self.predictor.predict(handcards_char, last_cards_char, prob_state)
print(intention)

def to_pokers(cards):
for i, card in enumerate(cards):
if card == '*':
cards[i] = 'w'
elif card == '$':
cards[i] = 'W'
elif card == '10':
cards[i] = '0'
return rule._to_pokers(self.hand_pokers, cards)
# if not self.table.last_shot_poker or self.table.last_shot_seat == self.seat:
# pokers.append(self.hand_pokers[0])
# else:
# pokers = rule.cards_above(self.hand_pokers, self.table.last_shot_poker)
pokers = to_pokers(intention)
packet = [Pt.REQ_SHOT_POKER, pokers]
# IOLoop.current().add_callback(self.to_server, packet)
IOLoop.current().call_later(2, self.to_server, packet)

0 comments on commit 2f5f42a

Please sign in to comment.