This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#301 2012-11-28 20:04:20

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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?  big_smile  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.  smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#302 2012-11-29 04:15:01

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

blob8108 wrote:

@Hardmath123: Can you send me the JS code now?  big_smile  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.  smile

Wonderful! (Are you sure you don't want a hand?  wink  )

I did, yes -- just GET /ais/ -- described here.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#303 2012-11-29 06:19:28

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#304 2012-11-29 06:25:14

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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).


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#305 2012-11-29 06:50:32

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Mer. You did run it from the root directory ("python server.py")?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#306 2012-11-29 09:13:09

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  smile

No worries  smile

And that sounds fun!  big_smile  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?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#307 2012-11-30 05:37:11

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Yeah, that's probably it. I'll try it out.  smile

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.  tongue


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#308 2012-12-01 02:57:53

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

Yeah, that's probably it. I'll try it out.  smile

Did it work?  smile

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.  tongue

Fair enough  tongue  But yeah, you build upward, and the pieces are small enough that you can see between them. So it does actually work, surprisingly.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#309 2012-12-01 21:32:33

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Cool. At this point, my sister is actually playing strategically, which is interesting because she's just three.  smile

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."  tongue ). I've had to study for a stupid biology test and then was told I'll most likely miss it.  sad


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#310 2012-12-01 22:14:19

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: AI Strategy Tournament: Rescheduled to June 1st

Awesome!  I really wish Google Docs had a "code" format, where you could collaborate on a program in realtime.  But, I guess that's what GitHub's for.  Still, Google wins.

Offline

 

#311 2012-12-02 04:32:08

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#312 2012-12-02 05:28:59

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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

 

#313 2012-12-02 06:07:36

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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!  smile

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.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#314 2012-12-02 06:22:55

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  hmm


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#315 2012-12-02 06:40:05

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  hmm

PIL
you can save and load to a .png file

Offline

 

#316 2012-12-02 06:51:08

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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...  tongue

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.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#317 2012-12-02 06:58:40

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#318 2012-12-02 07:53:15

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

Here's the JSsmile

That's really cool! I'll commit it into git, if that's okay. I love the 3D flip  big_smile  And I like the hexagons...  wink


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#319 2012-12-02 08:17:53

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

'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.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#320 2012-12-02 11:34:35

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#321 2012-12-02 11:50:00

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  smile

For the label thing the markup should be:

Code:

<label><input type=radio …>Label</label>
…

or:

Code:

<input type=radio id=radio1 …><label for=radio1>Label</label>
…

(please don't use the ID "radio1"!)

Not:

Code:

<input type=radio …><label>Label</label>
…

nXIII

Offline

 

#322 2012-12-02 20:00:27

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.  smile

P.S. I'm trying PyPng, it's not behaving, though.  hmm  I'll work on it.

Last edited by Hardmath123 (2012-12-02 20:01:19)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#323 2012-12-02 20:06:21

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

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.


nXIII

Offline

 

#324 2012-12-03 06:37:03

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: AI Strategy Tournament: Rescheduled to June 1st

Oh.

Yeah, I'll do that then. Thanks for the tip.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

Board footer