Skip to content

Instantly share code, notes, and snippets.

@BIGBALLON
Created July 10, 2018 13:32
Show Gist options
  • Save BIGBALLON/5d25a72e03fa1233e7b9e12f4ce9ea6a to your computer and use it in GitHub Desktop.
Save BIGBALLON/5d25a72e03fa1233e7b9e12f4ce9ea6a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import sys
import time
import random
import numpy as np
def debug_out(debug_str):
print("[DEBUG INFO] : ", debug_str)
def dummy_input(board_size,feature_dim):
data = np.zeros((1, feature_dim, board_size, board_size))
label_pn = 1
label_vn = 1
return np.asarray(data).astype('float32'), np.asarray(label_pn).astype('int32'), np.asarray(label_vn).astype('float32')
def decode(encode_str):
key_list = encode_str.split(",")
decode_list = []
for key in key_list:
key_str = bin(int(key))[2:].zfill(27)
for k in key_str:
if k == '1':
decode_list.append(1)
else:
decode_list.append(0)
return np.array(decode_list,dtype="float32")
def get_batch(
batch_x,
batch_pn,
batch_vn,
data_list,
board_size,
feature_dim,
batch_size
):
for i in range(batch_size):
data_str = data_list[i].split(" ");
batch_x[i] = decode(data_str[0]).reshape(feature_dim,board_size,board_size)
batch_vn[i] = float(data_str[1])
batch_pn[i] = int(data_str[2])
batch_pn = np.asarray(batch_pn,dtype='int32')
batch_vn = np.asarray(batch_vn,dtype='float32')
return batch_x, batch_pn, batch_vn
if __name__ == '__main__':
pass
void getEncodeFeature(NoGoDNNFeatureType featureType, vector<float> &feature, NoGoEncodeFeatrue &encodeFeature)
{
int featureSize = 3;
switch (featureType)
{
case FEATURE_BASE:
encodeFeature.m_encodeString.resize(2 * featureSize);
//TODO
break;
case FEATURE_WITH_LEGAL_MOVE:
encodeFeature.m_encodeString.resize(4 * featureSize);
for (int c = 0; c < 4; ++c){
int key = 0;
for (int i = 0; i < 27; ++i){
key <<= 1;
if(feature[c * 81 + i] == 1) key |= 1;
}
if (c) encodeFeature.m_encodeString += ',' + to_string(key);
else encodeFeature.m_encodeString = to_string(key);
key = 0;
for (int i = 27; i < 54; ++i){
key <<= 1;
if(feature[c * 81 + i] == 1) key |= 1;
}
encodeFeature.m_encodeString += ',' + to_string(key);
key = 0;
for (int i = 54; i < 81; ++i){
key <<= 1;
if(feature[c * 81 + i] == 1) key |= 1;
}
encodeFeature.m_encodeString += ',' + to_string(key);
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment