Skip to content

Commit

Permalink
modified for uncompiled running
Browse files Browse the repository at this point in the history
  • Loading branch information
duducheng committed Oct 6, 2018
1 parent 7a6f4c6 commit 2cf591a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 55 deletions.
2 changes: 1 addition & 1 deletion game2048/expectimax/_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
else:
print(
"Couldn't find 2048 library bin/2048.{so,dll,dylib}! Make sure to build it first.")
exit()
# exit()

ailib.init_tables()

Expand Down
100 changes: 50 additions & 50 deletions static/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,87 @@
<link href="static/style.css" rel="stylesheet">
<script src="static/vue.js"></script>
<script src="static/vue-resource.js"></script>
<link href="static/favicon.ico" rel="icon" type="image/x-icon"/>
<link href="static/favicon.ico" rel="icon" type="image/x-icon" />

</head>


<body>

<h1 align="center">2048 Game</h1>
<h4 align="center">Use ↑ ↓ ← → to play, any other keys for AUTO by your agent.</h4>
<h1 align="center">2048 Game</h1>
<h4 align="center">Use ↑ ↓ ← → to play, or any other keys for "AUTO-mode" by your agent.</h4>

<div class="container" id="app">
<div class="row row-content">
<div class="container" id="app">
<div class="row row-content">

<div class="col-xs-6">
<div class="col-xs-6">

<h1>
Score: {{score}}
</h1>
<h1>
Score: {{score}}
</h1>

</div>
</div>

<div class="col-xs-6" align="right">
<div class="col-xs-6" align="right">

<h1>
<span v-if="end==1">You lose!</span>
<span v-if="end==2">You win!</span>
</h1>
<h1>
<span v-if="end==1">You lose!</span>
<span v-if="end==2">You win!</span>
</h1>

</div>
</div>


<div class="col-xs-12">
<div class="col-xs-12">

<table align=center>
<tr v-for="row in board">
<td v-for="item in row">
<span v-if="item!=0">{{item}}</span>
</td>
</tr>
</table>
<table align=center>
<tr v-for="row in board">
<td v-for="item in row">
<span v-if="item!=0">{{item}}</span>
</td>
</tr>
</table>

</div>
</div>

<div class="col-xs-6">
<div class="col-xs-6">

<h3>
<span v-if="direction!=-1">Last move:</span>
<span v-if="direction==0"></span>
<span v-if="direction==1"></span>
<span v-if="direction==2"></span>
<span v-if="direction==3"></span>
</h3>
<h3>
<span v-if="direction!=-1">Last move:</span>
<span v-if="direction==0"></span>
<span v-if="direction==1"></span>
<span v-if="direction==2"></span>
<span v-if="direction==3"></span>
</h3>

</div>
</div>

<div class="col-xs-6" align="right">
<div class="col-xs-6" align="right">

<h3>
Controlled by {{control}}
</h3>
<h3>
Controlled by {{control}}
</h3>

</div>
</div>

</div>
</div>
</div>


<footer class="row-footer">
<div class="container">
<div class="row">
<div class="col-xs-12">
<h3 align=center>
Copyright © 2016-2018 <a href="https://github.com/duducheng">Jiancheng</a>
</h3>
<footer class="row-footer">
<div class="container">
<div class="row">
<div class="col-xs-12">
<h3 align=center>
Copyright © 2016-2018 <a href="https://github.com/duducheng">Jiancheng</a>
</h3>
</div>
</div>
</div>
</div>
</footer>
</footer>


<script src="static/app.js"></script>
<script src="static/app.js"></script>
</body>

</html>
19 changes: 15 additions & 4 deletions webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ def get_board():
GAME_SIZE = 4
SCORE_TO_WIN = 2048
APP_PORT = 5005
APP_HOST = "localhost"
APP_HOST = "0.0.0.0"

from game2048.game import Game
from game2048.agents import ExpectiMaxAgent

game = Game(size=GAME_SIZE, score_to_win=SCORE_TO_WIN)
agent = ExpectiMaxAgent(game=game)

try:
from game2048.agents import ExpectiMaxAgent
agent = ExpectiMaxAgent(game=game)
except:
from game2048.agents import RandomAgent
print("WARNING: Please compile the ExpectiMaxAgent first following the README.")
print("WARNING: You are now using a RandomAgent.")
agent = RandomAgent(game=game)

print("Run the webapp at http://<any address for your local host>:%s/" % APP_PORT)

app = get_flask_app(game, agent)
app.run(port=APP_PORT, threaded=False, host=APP_HOST) # IMPORTANT: `threaded=False` to ensure correct behavior


0 comments on commit 2cf591a

Please sign in to comment.