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

#276 2012-11-14 03:24:37

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

Actually, amcerbu, that means you agree with blob.

Well, I did quote you agreeing with me — maybe amcerbu was referring to that?  tongue

Hardmath123 wrote:

Hexagons. What do you think?

Nice! Doesn't look quite regular, but I'm sure you can tweak it a little. You are completely insane using CSS, though.  tongue

Hardmath123 wrote:

I don't see why you need board_size (you have the actual board to find that out yourself, right?).

amcerbu wrote:

I firmly believe that field size should be a property that can be changed, and that isn't implementation-specific (size becomes another one of the variables "fed" to AI code).  A perfect AI should be able to play on a field of any size.

Hardmath123 wrote:

Nah, I think that's over-complicating. Same for the board size; let's stick with one value.

Amcerbu's right: you're going to have a board_size variable in your JS anyway, so it might as well be tweakable. And sending it along with every request just means I don't have to sqrt(len(board)).

We probably should implement the pie rule, too. It shouldn't be too difficult — and now we have an AI class we can just add new functions to it.

That's a good point — I can just flip the board on the Python end, since it's only needed for the AIs. Done!

Revised protocol:

/ai/getmove
  * board_size = 17 (or whatever)
  * board = "0R00000BB00BRR..."
  * AI = "blob8108"
  * alternate_player = 0 (or 1)
returns JSON:
  { x: 5,
    y: 7,
    time_taken: 3.393709897994995 }

Can we start coding now?  big_smile

Last edited by blob8108 (2012-11-14 03:25:35)


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

Offline

 

#277 2012-11-14 03:52:36

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

Re: AI Strategy Tournament: Rescheduled to June 1st

What's alternate_player?

For the pie rule, let's just make that a simple extra function which we define in out AI class optionally (it should be predefined as return False in the base class).

Here's what the base class should look like, I guess:

Code:

class BaseAI():
    PLAYER_NAME = "Hardmath123"
    def __init__(self):
        pass
    
    def PieRule(self,board):
        """PIE Rule decision making: return true to agree to swap; false to disagree."""
        return False
    def Move(self,board):
        """Return a tuple of (X,Y) containing where you move."""
        return (-1,-1)

I also need an API call which lists all available AIs, for my menu. Thanks.

It is OK if I go crazy with HTML5 and not really care about IE? I'll try to support FF and Webkit, since anyone smart enough to be doing this competition is clearly above IE.

Anyway, let's start coding. Gentlemen, start your Xcodes!  smile

Last edited by Hardmath123 (2012-11-14 03:56:51)


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

Offline

 

#278 2012-11-14 11:31:37

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

What's alternate_player?

How I know whether to flip the board or not. Call it player = "red" (or "blue") if you like.

So, the interface:

GET /ais
  => list of AIs: [{'name': 'blob8108'}, ...]

POST /ais/blob8108/move
  => get move {'x': 1, 'y': 2, 'time_taken' etc} (discussed earlier)

POST /ais/blob8108/pie_rule
  => returns {'swap': 1} (0 otherwise)

Slightly revised base class:

Code:

class BaseAI(object):
    name = "Hardmath123"

    def pie_rule(self, board):
        """Pie rule decision making: return true to agree to swap; false to keep playing."""
        return False

    def move(self, board):
        """Return a tuple of (X,Y) containing where you move."""
        return (5, 7)

It is OK if I go crazy with HTML5 and not really care about IE? I'll try to support FF and Webkit, since anyone smart enough to be doing this competition is clearly above IE.

Crazy HTML5 is cool. I'm sure IE9 will kinda-sorta work anyway. *facepalm* Oh, wait, you're using weird hacky CSS...  tongue

Anyway, let's start coding. Gentlemen, start your Xcodes!  smile

Great! Although I object to "Xcodes". Let's not discriminate here...  tongue

Last edited by blob8108 (2012-11-14 14:10:18)


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

Offline

 

#279 2012-11-14 17:34:33

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Regular! (I was bored  tongue )

Last edited by nXIII (2012-11-14 17:35:00)


nXIII

Offline

 

#280 2012-11-14 17:57:04

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

Re: AI Strategy Tournament: Rescheduled to June 1st

nXIII wrote:

Regular! (I was bored  tongue )

Woop!  big_smile


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

Offline

 

#281 2012-11-14 20:59:48

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

Re: AI Strategy Tournament: Rescheduled to June 1st

nXIII wrote:

Regular! (I was bored  tongue )

Nice!

Offline

 

#282 2012-11-15 06:48:55

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

Re: AI Strategy Tournament: Rescheduled to June 1st

nXIII wrote:

Regular! (I was bored  tongue )

Showoff.  tongue


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

Offline

 

#283 2012-11-17 14:28:10

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

Re: AI Strategy Tournament: Rescheduled to June 1st

@Hardmath123: how's it going?  smile


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

Offline

 

#284 2012-11-17 19:59:46

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Well...

I got the menu working, you can now pick who plays as black or white. There's also a field for board size. When you click the next button a really sweet CSS 3D flip ( big_smile ) happens and you have a new game board.

What is the largest board size you want to support? I'm having sizing issues with CSS. Maybe just have two options, SMALL and BIG? I'd like the hexagons to be centered and X-axis-rotated a few degrees for a cool perspective look, but that goes crazy if I have more than 15 hexagons — can we make that an upper limit?  smile

How's the Python going? I was wondering if you could implement a timeout after 15 seconds which automatically returned (-1,-1). I don't know how one would do that though.  hmm


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

Offline

 

#285 2012-11-21 03:32:33

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

Re: AI Strategy Tournament: Rescheduled to June 1st

I was really hoping to finish some Python before I replied to your post, but that's not going to happen.  sad

Hardmath123 wrote:

I got the menu working, you can now pick who plays as black or white. There's also a field for board size. When you click the next button a really sweet CSS 3D flip ( big_smile ) happens and you have a new game board.

Sweet  big_smile

What is the largest board size you want to support? I'm having sizing issues with CSS. Maybe just have two options, SMALL and BIG? I'd like the hexagons to be centered and X-axis-rotated a few degrees for a cool perspective look, but that goes crazy if I have more than 15 hexagons — can we make that an upper limit?  smile

It'd be nice to experiment with board sizes all the way up to 19 or so.  smile

How's the Python going? I was wondering if you could implement a timeout after 15 seconds which automatically returned (-1,-1). I don't know how one would do that though.  hmm

I'm sure a timeout is possible to do in Twisted — I think it should be higher, though: maybe 60 seconds. I now have a Board class, complete with flipping, and the HTTP calls were easy to add; I just haven't hooked them up yet.  tongue  But I'll be done "soon"...

Here's the revised interface, btw!

Code:

GET /ais/
    Return a list of AIs.
    
    eg  {'ais': [
            {'name': 'blob8108'},
            ...
        ]}


POST /ais/blob8108/move

    Return the position to place a piece.

    Arguments:
        board -- as string
            (can be left empty)
        player -- either "RED" or "BLUE"
            (all AI code assumes it plays left-to-right, as RED. If
            player=BLUE, the Board is flipped behind-the-scenes, as is the
            result.)

    Returns:
        {
            'x': 5,
            'y': 7,
            'time_taken': 3.32002,
        }


POST /ais/blob8108/will_swap

    Whether the AI wishes to swap with the other player (pie rule).
    Called after the first move.
    
    This is used to ensure fairness, by giving the second player the chance
    to exchange places with the first player. (This ensures the first
    player's move will be neutral.)
    
    Arguments:
        board -- as string.

    Returns:
        {'swap': 1}  -- to swap with the other player
        {'swap': 0}  -- to continue playing as-is

Last edited by blob8108 (2012-11-21 03:33:47)


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

Offline

 

#286 2012-11-21 05:40:54

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Great, that's a lot more progress than I've managed.  smile

My actual life has suddenly started getting too busy for my liking; so I'm not getting much coding time.  sad


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

Offline

 

#287 2012-11-21 05:54:07

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

Great, that's a lot more progress than I've managed.  smile

No, no; it sounds like you've done much more than me  tongue

My actual life has suddenly started getting too busy for my liking; so I'm not getting much coding time.  sad

I've got an interview at Cambridge in a couple of weeks, which is the perfect excuse to spend all my time coding and learning about algorithms. I'm hoping to try miniLD this weekend...  big_smile


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

Offline

 

#288 2012-11-21 19:58:13

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Cool. Good luck!  smile


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

Offline

 

#289 2012-11-21 20:23:52

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

Re: AI Strategy Tournament: Rescheduled to June 1st

blob8108 wrote:

I've got an interview at Cambridge in a couple of weeks, which is the perfect excuse to spend all my time coding and learning about algorithms. I'm hoping to try miniLD this weekend...  big_smile

Cool!  Cambridge, England, or Cambridge, Massachusetts?  Good luck!

Offline

 

#290 2012-11-22 15:06:47

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Thanks, both of you!  smile

amcerbu wrote:

Cambridge, England, or Cambridge, Massachusetts?

Good question! The one in England (I live in the UK). Although my friend did try and convince me to apply to MIT...  tongue


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

Offline

 

#291 2012-11-23 14:52:24

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

Re: AI Strategy Tournament: Rescheduled to June 1st

I'm nearly done, I think!  smile  I've thrown in lots of errors to hopefully make debugging the HTTP interface easier.

How are you doing? Are you ready to try some integration testing?  big_smile


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

Offline

 

#292 2012-11-26 07:37:33

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Great! I still need to debug a bit and make a few tweaks (my hexagons are currently squares), and add win detection. But overall it's working out well. I was pleasantly surprised at how easy the server-integration was (I wrote a simple server to make me input the "ai" results manually for testing).  smile


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

Offline

 

#293 2012-11-26 10:39:32

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

Great! I still need to debug a bit and make a few tweaks (my hexagons are currently squares), and add win detection. But overall it's working out well.

Good! Heh, square hexagons  tongue


I was pleasantly surprised at how easy the server-integration was (I wrote a simple server to make me input the "ai" results manually for testing).  smile

I might as well send you the Python server, I suppose  smile  I'll upload it to Github tonight...


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

Offline

 

#294 2012-11-28 02:41:33

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Pushedsmile


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

Offline

 

#295 2012-11-28 05:47:00

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Yay! Lemme download it...


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

Offline

 

#296 2012-11-28 06:04:10

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Well, it works pretty well. Now I need to get my JS working right and we're ready to roll!

Mind explaining how to use the base AI class (and get it on the server) here for all participants?  smile

Last edited by Hardmath123 (2012-11-28 06:04:33)


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

Offline

 

#297 2012-11-28 06:15:37

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Ah, I'd forgotten about AI importing. I'll do that later...  tongue

Do you have a Github?


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

Offline

 

#298 2012-11-28 07:29:13

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

Re: AI Strategy Tournament: Rescheduled to June 1st

No.


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

Offline

 

#299 2012-11-28 11:26:00

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

Re: AI Strategy Tournament: Rescheduled to June 1st

Hardmath123 wrote:

No.

Ah. I can't add you as a collaborator, then.  sad


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

Offline

 

#300 2012-11-28 14:20:55

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

Re: AI Strategy Tournament: Rescheduled to June 1st

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?

Last edited by blob8108 (2012-11-28 14:21:43)


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

Offline

 

Board footer