[Home]MoonShadow/Solitaire

ec2-44-220-44-148.compute-1.amazonaws.com | ToothyWiki | MoonShadow | RecentChanges | Login | Webcomic

Click [here] to play.

ToothyGDL
logic
{
 array board 
      { 2, 2, 1, 1, 1, 2, 2,
        2, 2, 1, 1, 1, 2, 2,
        1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 0, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1,
        2, 2, 1, 1, 1, 2, 2,
        2, 2, 1, 1, 1, 2, 2 }

 int win { 0 }
 int left { (7*7)-(4*4)-1 }
 int selected { -1 }
 int _save_slot { 0 }

 for i ( 0 .. ((7*7)-1) )
 {
    when 
    {
      (selected == -1)
      and
      (board[i] == 1)
      and 
      (
        ( ( (i % 7) < 5 ) and (board[i+1] == 1) and (board[i+2] == 0) )
        or
        ( ( i < 35 ) and (board[i+7] == 1) and (board[i+14] == 0) )
        or
        ( ( (i % 7) > 1 ) and (board[i-1] == 1) and (board[i-2] == 0) )
        or
        ( ( i > 14 ) and (board[i-7] == 1) and (board[i-14] == 0) )
      )
    }
    allow { selected = i; }
    label { "select " i }
 }
 
 when
 {
  ( selected != -1 )
  and 
  ( ( (selected % 7) < 5 ) and (board[selected+1] == 1) and (board[selected+2] == 0) )
 } 
 allow
 {
   board[selected] = 0;
   board[selected+1] = 0;
   board[selected+2] = 1;
   left = left - 1;
   selected = -1;
 }
 label
 {
   "jump " (selected+2)
 }

 when
 {
  ( selected != -1 )
  and 
  ( ( (selected % 7) > 1 ) and (board[selected-1] == 1) and (board[selected-2] == 0) )
 } 
 allow
 {
   board[selected] = 0;
   board[selected-1] = 0;
   board[selected-2] = 1;
   left = left - 1;
   selected = -1;
 }
 label
 {
   "jump " (selected-2)
 }

 when
 {
  ( selected != -1 )
  and 
  ( ( selected < 35 ) and (board[selected+7] == 1) and (board[selected+14] == 0) )
 } 
 allow
 {
   board[selected] = 0;
   board[selected+7] = 0;
   board[selected+14] = 1;
   left = left - 1;
   selected = -1;
 }
 label
 {
   "jump " (selected+14)
 }

 when
 {
  ( selected != -1 )
  and 
  ( ( selected > 14 ) and (board[selected-7] == 1) and (board[selected-14] == 0) )
 } 
 allow
 {
   board[selected] = 0;
   board[selected-7] = 0;
   board[selected-14] = 1;
   left = left - 1;
   selected = -1;
 }
 label
 {
   "jump " (selected-14)
 } 

 when
 {
  ( selected != -1 )
 }
 allow
 {
   selected = -1;
 }
 label
 {
   "unselect " selected
 }

 when
 {
  ( left == 1 )
 }
 allow
 {
   win = 1;
 }
 label
 {
   "win"
 }
}

display
{
  stringtable counters { " ", "*", " " }

  for i ( 0 .. ((7*7)-1) )
  {
    box
    {
     width { 2em }
     height { 2em }
     border { 1px solid black }
     content { counters[ board[i] ] }
     bind_action { "select " i }
     bind_action { "unselect " i }
     bind_action { "jump " i }
     while_active { background { green } }
     if( board[i] == 2 ) { background { #fe7 } }
    }
    
    if( (i % 7) == 6 )
    {
      newline
    }
  }

  newline
    
  box
  {
     bind_action { "win" }
     while_active { background { green } content { "Well done!" } }
  }
}


[Recompile this page]
[Compiler error log]

Bug observed:
 * * b
. . .
a . .
The top-left star is able to move to empty space a as well as b.
Fixed - ta.. :) - MoonShadow
Fascinating language though; I'll give some thought to whether there's anything I want to do in it  :) --AC
Well, I'll bung it into the wiki, and how much else I do to it will depend on the level of interest.. - MoonShadow

Bug observed (EditConflict - and fixed. Ta!):
     . . *
    * . a
* * * * * . *
* * * * # * *
Piece at position # is marked as movable, but once selected can't move to empty space at a. Or anywhere else. Neat though. In keeping with the ChrisHowlett/ExaltedStatsGenerator, let's go for ambitious straight off: I wonder if I can program Chess in it? --CH
I was thinking one might go about doing Chess much the same way as Solitaire, actually, which would make it quite simple to write (though somewhat tedious; some form of preprocessing is definitely going to be required for the longer rulesets, I think): for each space on the board, whenever it contains a piece belonging to the current player, allow the player to select it; for each possible chess move for each kind of piece, whenever there is a piece of that kind selected and the move is legal, allow the player to perform the move (which also causes the current player to change). Draughts would share the same code except for having a different set of legal moves.. - MoonShadow
A still-more insane thought came to me. This syntax is (almost certainly) enough to program a RogueLike... But I don't think I'll try. --CH
Again, you'd probably want a pass through a preprocessor. Otherwise it'd get horribly messy if it's at all complex, because you'd be repeating sequences of code like location=(y*width)+x all over the place. Maybe I'll have time to add one this weekend. But yes, in principle.. - MoonShadow

Not really a bug, but the empty spaces should still have borders, to distinguish them from spaces ooudside the board that can't be jumped to. --Edwin
Hm, yes. I was thinking the spaces that can be jumped to become highlighted so we don't need to do that, but actually once a significant number of the counters has gone it becomes hard to see the board. Perhaps making the spaces that can't be jumped to have a non-white background colour might be better, though - I quite like the black borders around counters.. - MoonShadow

ec2-44-220-44-148.compute-1.amazonaws.com | ToothyWiki | MoonShadow | RecentChanges | Login | Webcomic
Edit this page | View other revisions | Recently used referrers
Last edited October 14, 2005 1:29 pm (viewing revision 21, which is the newest) (diff)
Search: