def get_children(pos, mtm): # mtm true if i am moving if pos not in childrens: relevant = bb.get_relevant(pos) pos_score = get_score(pos) m_bb = bb.pos_to_m_bb(pos) o_bb = bb.pos_to_o_bb(pos) children = [ do_placement(pos, i, mtm, pos_score, m_bb, o_bb) for i in range(64) if bb.get_i(relevant, i) ] #for i in range(64): # if bb.get_i(relevant, i): # n_pos = bb.pos_place_i(pos, i, mtm) # if n_pos not in scores: # n_m_bb, n_o_bb = bb.pos_to_bb(n_pos) # pre_prow_score = bb.score_prow_i(m_bb, o_bb, i) - bb.score_prow_i(o_bb, m_bb, i) # post_prow_score = bb.score_prow_i(n_m_bb, n_o_bb, i) - bb.score_prow_i(n_o_bb, n_m_bb, i) # scores[n_pos] = pos_score - pre_prow_score + post_prow_score # children.append(n_pos) children.sort(key=lambda c: scores[c], reverse=mtm) childrens[pos] = children return childrens[pos]
def do_placement(pos, i, mtm, pos_score, m_bb, o_bb): n_pos = bb.pos_place_i(pos, i, mtm) if n_pos not in scores: n_m_bb = bb.pos_to_m_bb(n_pos) n_o_bb = bb.pos_to_o_bb(n_pos) pre_prow_score = bb.score_prow_i(m_bb, o_bb, i) - bb.score_prow_i( o_bb, m_bb, i) post_prow_score = bb.score_prow_i(n_m_bb, n_o_bb, i) - bb.score_prow_i( n_o_bb, n_m_bb, i) scores[n_pos] = pos_score - pre_prow_score + post_prow_score return n_pos
def score_move(pos, i, mtm): # mtm true if i am moving new_m_score = m_scores[pos] new_o_score = o_scores[pos] m_bb = bitboard.pos_to_m_bb(pos) o_bb = bitboard.pos_to_o_bb(pos) new_m_score -= score_i(m_bb, o_bb, i) new_o_score -= score_i(o_bb, m_bb, i) if mtm: m_bb = bitboard.place_i(m_bb, i) else: o_bb = bitboard.place_i(o_bb, i) new_m_score += score_i(m_bb, o_bb, i) new_o_score += score_i(o_bb, m_bb, i) new_pos = bitboard.bb_to_pos(m_bb, o_bb) m_scores[new_pos] = new_m_score o_scores[new_pos] = new_o_score return new_m_score - new_o_score
def get_score(pos): if pos not in scores: m_bb = bb.pos_to_m_bb(pos) o_bb = bb.pos_to_o_bb(pos) scores[pos] = bb.score_bb(m_bb, o_bb) - bb.score_bb(o_bb, m_bb) return scores[pos]