Skip to content

Commit 6ad4297

Browse files
committed
implement remote game and use of AI
1 parent f1b5332 commit 6ad4297

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "alphagomoku/deep_learning"]
2+
path = alphagomoku/deep_learning
3+
url = git://github.com/AlphaGomoku/deep_learning.git

alphagomoku/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
from flask import Flask, g, render_template
1+
from flask import Flask, g, render_template, request, jsonify
2+
3+
import os
4+
import sys
5+
print(os.path.dirname(os.path.abspath(__file__)))
6+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
7+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'deep_learning'))
8+
from deep_learning.query import QueryManager
29

310

411
def create_app():
512
app = Flask(__name__)
613

14+
qm = QueryManager()
15+
716
@app.errorhandler(404)
817
def not_found(error):
918
return render_template('404.html')
@@ -17,4 +26,13 @@ def server_error(error):
1726
def index():
1827
return render_template('index.html')
1928

29+
@app.route('/get_go', methods=['POST'])
30+
def get_go():
31+
state = request.form.getlist('state[]')
32+
state = [int(s) for s in state]
33+
res = qm.query(state)
34+
ret = (res//15,res%15)
35+
36+
return jsonify(ret)
37+
2038
return app

alphagomoku/deep_learning

Submodule deep_learning added at eeb4203

alphagomoku/static/js/Interface.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ function SetGo(x,y){ //x,y 에 돌 넣기.
66

77
function MapState(){ //Map 변수 반환받기
88
return Map;
9-
}
9+
}
10+
11+
function MapState1D(){
12+
map2D = MapState();
13+
map1D = [];
14+
15+
var cnt = 0;
16+
for (var i = 0; i < map2D.length; ++i) {
17+
for (var j = 0; j < map2D[0].length; ++j) {
18+
map1D[cnt++] = map2D[i][j];
19+
}
20+
}
21+
return map1D;
22+
}
1023

1124
function PrintMap(){ //Map 변수 확인
1225
for(var n=0;n<15;n++){

alphagomoku/templates/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
// 바둑돌 놓기
6565
$('svg').on('click', function(e) {
66+
6667
var loc = cursorPoint(e)
6768
loc.x = Math.round((loc.x+5)/10)*10-5
6869
loc.y = Math.round((loc.y+5)/10)*10-5
@@ -74,7 +75,23 @@
7475
}
7576
$('span#point_x').text(loc.x/10);
7677
$('span#point_y').text(loc.y/10);
78+
79+
GoAI()
80+
})
81+
82+
function GoAI() {
83+
$.ajax({
84+
url: "/get_go",
85+
type: "post",
86+
data: {
87+
state: MapState1D()
88+
},
89+
success: function(result) {
90+
console.log(result);
91+
setGo(result[1], result[0]);
92+
}
7793
})
94+
}
7895

7996
function setGo(x,y){
8097
var svg = document.querySelector('svg');

0 commit comments

Comments
 (0)