blob8108 wrote:
Here, I updated it to add AI loading. Each AI lives in its own module.
To create an AI: Copy _template.py to a new file (<username>.py, inside the "ais" folder), and fill in the "move" and "will_swap" functions.
You can define your own helper functions in the file, too: the loader will just ignore them. (You might want to share code between "move" and "will_swap", for example, using a third function.)
The provided "board" is a hex.Board object (defined here). Useful stuff:
indexing: board[x][y]
get size: board.size
copying: board.copy()
(You'll probably want to copy it if you're using some kind of recursive algorithm to analyse moves, for example.)@Hardmath123: Can you send me the JS code now? Oh, and should we update the first post?
The JS is still (embarrassingly) buggy, and there's no win detection. I'll work on it over the weekend and hopefully have a polished code on gdocs. Also, did you implement the GET_AIs function? I use a pair of radio-buttons-lists as my inputs.
Offline
Hardmath123 wrote:
blob8108 wrote:
@Hardmath123: Can you send me the JS code now? Oh, and should we update the first post?
The JS is still (embarrassingly) buggy, and there's no win detection. I'll work on it over the weekend and hopefully have a polished code on gdocs. Also, did you implement the GET_AIs function? I use a pair of radio-buttons-lists as my inputs.
Wonderful! (Are you sure you don't want a hand? )
I did, yes -- just GET /ais/ -- described here.
Offline
I'm fine. Get /ais or /ais/?
P.S. I'll try to finish it by Monday (on which I'm not going to be in school, so I'll have a bunch of homework to catch up with, too). Right now my parents are making me play Tic-Tac-Toe with my 3-year-old sister.
Offline
It's not working. First of all, it seems to not recognize the "ais" module (you may need a blank __init__.py in the ais folder). Once I added the __init__.py file, it couldn't find the folder /ais, probably because instead of looking for the relative path, it tried to find it from the root directory (/Users/*/ais or something).
Offline
Mer. You did run it from the root directory ("python server.py")?
Offline
Hardmath123 wrote:
I'm fine. Get /ais or /ais/?
Either should be fine.
P.S. I'll try to finish it by Monday (on which I'm not going to be in school, so I'll have a bunch of homework to catch up with, too). Right now my parents are making me play Tic-Tac-Toe with my 3-year-old sister.
No worries
And that sounds fun! Have you tried it in 3D, yet?
it seems to not recognize the "ais" module (you may need a blank __init__.py in the ais folder).
Whoops — I had one that I thought I didn't need; turned out I still had an __init__.pyc floating around :s
Once I added the __init__.py file, it couldn't find the folder /ais, probably because instead of looking for the relative path, it tried to find it from the root directory (/Users/*/ais or something).
I just tried it again (adding __init__.py) and it works fine for me. It assumes you're in the same directory as server.py — maybe that could be it?
Offline
Yeah, that's probably it. I'll try it out.
3D Tic-Tac-Toe sounds hard... how do you see pieces buried into the middle?
Anyway, my sister has a hard enough time with 2D.
Offline
Hardmath123 wrote:
Yeah, that's probably it. I'll try it out.
Did it work?
3D Tic-Tac-Toe sounds hard... how do you see pieces buried into the middle?
Anyway, my sister has a hard enough time with 2D.
Fair enough But yeah, you build upward, and the pieces are small enough that you can see between them. So it does actually work, surprisingly.
Offline
Cool. At this point, my sister is actually playing strategically, which is interesting because she's just three.
It did work, so I guess now we're really waiting for me. Are you OK if I put up a simple, functional thing on gdocs and we can improve it while we're making the AIs? I'm feeling rather guilty not being able to keep up (In the words of Douglas Adams, "I love deadlines. I love the whooshing sound they make as they go by." ). I've had to study for a stupid biology test and then was told I'll most likely miss it.
Offline
Hey blob, I'm writing a ray tracer (actually, I'm almost done with it), and I need a good format to output (and input) images as arrays of pixels. Do you know of a good library to read and write images? I'd be fine with an easy-to-use Mac-compatible format, too. Would SVG be good?
Right now, I'm (stupidly) writing a JSON list-of-list format which runs into 3MB for a simple 100x100 image. I wrote a JS script to output the image by reading it via canvas.
Offline
Hardmath123 wrote:
Hey blob, I'm writing a ray tracer (actually, I'm almost done with it), and I need a good format to output (and input) images as arrays of pixels. Do you know of a good library to read and write images? I'd be fine with an easy-to-use Mac-compatible format, too. Would SVG be good?
Right now, I'm (stupidly) writing a JSON list-of-list format which runs into 3MB for a simple 100x100 image. I wrote a JS script to output the image by reading it via canvas.
python of js?
if js, why not use base64?
Offline
Hardmath123 wrote:
Are you OK if I put up a simple, functional thing on gdocs and we can improve it while we're making the AIs?
Yeah, sounds great!
Hardmath123 wrote:
Hey blob, I'm writing a ray tracer (actually, I'm almost done with it), and I need a good format to output (and input) images as arrays of pixels. Do you know of a good library to read and write images? I'd be fine with an easy-to-use Mac-compatible format, too. Would SVG be good?
I thought the canvas API had a way of exporting an image? And a quick google found canvas2image.
I thought SVG was a vector format, and so not good for bitmaps.
Offline
Oh, I'm sorry. I assumed you knew I was making this in Python, which in retrospect isn't clear at all. Sorry.
Yeah, so I want to use Python to export a list-of-list-of-colors as an image. Any ideas?
P.S. I'll try and get the JS up by tomorrow. I found a weird bug with the AJAX which in bot-vs-bot mode keeps playing the game even once it's over.
Offline
Hardmath123 wrote:
Oh, I'm sorry. I assumed you knew I was making this in Python, which in retrospect isn't clear at all. Sorry.
Yeah, so I want to use Python to export a list-of-list-of-colors as an image. Any ideas?
P.S. I'll try and get the JS up by tomorrow. I found a weird bug with the AJAX which in bot-vs-bot mode keeps playing the game even once it's over.
PIL
you can save and load to a .png file
Offline
Hardmath123 wrote:
Oh, I'm sorry. I assumed you knew I was making this in Python, which in retrospect isn't clear at all. Sorry.
You mentioned JS/canvas, so I assumed...
Yeah, so I want to use Python to export a list-of-list-of-colors as an image. Any ideas?
Yeah, try PIL, or the slower but pure-Python PyPNG.
Offline
Offline
Hardmath123 wrote:
That's really cool! I'll commit it into git, if that's okay. I love the 3D flip And I like the hexagons...
Offline
'k, thanks. Can you try it out on FF and Chrome? It should definitely work on Chrome, not so sure on FF. Tested on Safari.
Offline
Hardmath123 wrote:
'k, thanks. Can you try it out on FF and Chrome? It should definitely work on Chrome, not so sure on FF. Tested on Safari.
Chrome works fine.
Firefox: flipping is a little strange.
I've fixed it now, though! I'm afraid I made a few minor tweaks to your code (trivial things like changing red/blue to white/black). I made a little todo list, feel free to amend it.
Offline
blob8108 wrote:
I've fixed it now, though! I'm afraid I made a few minor tweaks to your code (trivial things like changing red/blue to white/black). I made a little todo list, feel free to amend it.
For the label thing the markup should be:
<label><input type=radio …>Label</label> …
or:
<input type=radio id=radio1 …><label for=radio1>Label</label> …
(please don't use the ID "radio1"!)
Not:
<input type=radio …><label>Label</label> …
Offline
I know, the labels were linked in the beginning. Then I realized that if I was generating these dynamically, I'd need to create a bunch of dynamic ids, which I put off for later. So that goes on the to-do list.
@blob: that looks pretty complete.
P.S. I'm trying PyPng, it's not behaving, though. I'll work on it.
Last edited by Hardmath123 (2012-12-02 20:01:19)
Offline
Hardmath123 wrote:
Then I realized that if I was generating these dynamically, I'd need to create a bunch of dynamic ids, which I put off for later. So that goes on the to-do list.
<label><input>Label</label>. No IDs.
Offline
Oh.
Yeah, I'll do that then. Thanks for the tip.
Offline