1. Help with coding

Dear Euphoria Programmers, I am working on a program for Checkers, not 
to acutually play checkers, but to show the moves in a game. I need help 
with designing something to allow it to move the checker pieces over the 
board with the click of a button. If anyone would be willing to help, 
please reply, I will be very greatful, thanks guys
Trav

new topic     » topic index » view message » categorize

2. Re: Help with coding

On Friday 20 July 2001 11:39, Travis Weddle wrote:

> Dear Euphoria Programmers, I am working on a program for Checkers, not
> to acutually play checkers, but to show the moves in a game. I need help
> with designing something to allow it to move the checker pieces over the
> board with the click of a button. If anyone would be willing to help,
> please reply, I will be very greatful, thanks guys
> Trav

Could you be more specific? The way you would do this in Windows is 
very different from the way it would be done in DOS, or in Linux. 

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

3. Re: Help with coding

On Friday 20 July 2001 12:05, Travis Weddle wrote:

> I would like this to be in Windows... what else do i need to be specific
> on (i'm not being sarcastic)
>
> irvm at ellijay.com wrote:
> > On Friday 20 July 2001 11:39, Travis Weddle wrote:
> > > Dear Euphoria Programmers, I am working on a program for Checkers, not
> > > to acutually play checkers, but to show the moves in a game. I need
> > > help with designing something to allow it to move the checker pieces
> > > over the board with the click of a button. If anyone would be willing
> > > to help, please reply, I will be very greatful, thanks guys
> > > Trav

A good place to start would be with Dave Cuny's GlassWorks game 
http://www.RapidEuphoria.com/glass.zip
It's a board game where you 'jump' pieces, not unlike checkers.
Dave's code is pretty well commented.  

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

4. Re: Help with coding

On Friday 20 July 2001 13:36, Travis Weddle wrote:

> Irv, yes, this is similar, but not exactly what i'm looking for, i need
> the program to be able to read a list of moves (i.e. 11-15 meaning piece
> on square 11 moves to square 15) and have a Previous and Next push
> buttons to go through the list (the pieces move on the click of a
> button, to the next move, or previous)

What part do you need help with - creating the window itself, 
placing the bitmaps, reading the list of moves, or applying the 
moves? 

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

5. Re: Help with coding

On Friday 20 July 2001 20:04, Travis Weddle wrote:

> I really need help on reading the list of moves and applying them, i can
> get the window, and i'm pretty sure i can set all the bitmaps where they
> need to be. (that is if it allows a bitmap to be placed over a bitmap?)

There are probably a dozen ways to do this, here's one:
If you use a plain text file for the moves: 
11, 15
23, 26
...
etc., with the numbers separated either by commas or by 
spaces, like this:
11 15
23 26
...
then I would suggest just reading them into a list:

include file.e
include get.e

constant SOURCE = 1, DESTINATION = 2 
atom fn
object source, destination
sequence moves

fn = open("moves.txt","r")
moves = {}
while 1 do
  source = get(fn) -- get the first number
  if source[1] = -1 then exit -- EOF
  else
     destination = get(fn) -- get the second number
     moves =  append(moves,{source[2],destination[2]})
  end if
end while
close(fn)
? moves

This gives a list like the following:
{{11,15},{23,26},{26,35},{52,44}}    

You can set a pointer to the start of the list, and advance it 
when the "next" button is pushed.

Going forward thru the list should be simple; increment the 
pointer by 1, and move checker from move[pointer][SOURCE] to 
move[pointer][DESTINATION], 
Backing up would seem to call for first undoing the move most 
recently made, which will be at the current pointer.
You can probably do that by simply reversing the source 
and destination, i.e. move checker from move[pointer][DESTINATION] to 
move[pointer][SOURCE].  Then decrement the pointer.
Don't let the pointer go below 1, or higher than the length of 
the moves list.

Before either move, you'll have to find out which color checker 
is being moved, so you can show the correct bitmap at the 
new location.

How to do that? There's probably a way you could get the info 
from windows, but it may be easier to just keep an array and 
update it with every move.  That will also have value if in the 
future you want to add the ability to check for legal moves,
be able to save and restore a game, etc.

Something like:
sequence a = repeat(0,64) 
-- where 0 means empty, 1 = black, -1 = red

a[1..16] = 1
a[49..64] = -1

with each move:
a[destination] = a[source] -- copies the color of checker into dest.
a[source] = 0 -- empties source square.

when drawing the checker, 
if a[DESTINATION] = -1 then -- use red checker bmp
else -- use black checker bmp.

I'm not sure about Windows, but you may be able to put both 
colors of checker in each square, and only show the color 
you want there (or none at all)

Hope that helps,
Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

6. Re: Help with coding

On Saturday 21 July 2001 16:24, Travis Weddle wrote:

> Ok--I think I some what understand where this is headed, now what i need
> to know is how do i "link" the pushbuttons with the actions, and the
> checker pieces to move them.?

Since you're asking this, I'm guessing that you aren't using 
Judith's IDE. If you were, you would just click on the button and
enter your code in the event window that pops up. The IDE makes 
the layout of a program such as this a 5 minute job. 

What you want to do is to add your bitmap display/hide code to 
the onClick[] events for the "Next" and "Prev" buttons.  

For the "Next" button, it would be something like:
 1. increment the move pointer by 1
 2. get the color of the checker in [SOURCE] square
 3. hide the source checker (or put a blank bitmap there)
 4. put the proper color checker in the [DESTINATION] square

For the "Prev" button, the code would be slightly different:
 1. swap {SOURCE] and [DESTINATION] -- to undo the last move
 2. get the color of the checker in the [SOURCE] square
 3. hide the source checker
 4. put the proper color checker in [DESTINATION]
 5. decrement the move pointer by 1

Note that steps 2, 3 and 4 in the "Prev" code are exactly the 
same as steps 2,3 and 4 in the "Next" code. That means 
those steps could be written only once, as a separate procedure,
so you wouldn't have to write and debug twice.  That simplifies 
your onClick event code:

procedure NextButton_onClick ()
if pointer < length(move) then 
  pointer += 1
  MoveChecker(move[pointer])
end if
end procedure
onClick[NextButton] = routine_id("NextButton_onClick")

procedure PrevButton_onClick ()
 MoveChecker({move[pointer][DESTINATION],
                       move[pointer][SOURCE]}) -- this swaps the order
 if pointer > 1 then
    pointer -= 1 
 end if
end procedure
onClick[PrevButton] = routine_id("PrevButton_onClick")

You don't actually need to link the checker pieces in any way, unless 
you want to move them by clicking on them. 

Hope this helps,
Irv

new topic     » goto parent     » topic index » view message » categorize

7. Re: Help with coding

On Sunday 22 July 2001 12:49, Travis Weddle wrote:

> Thanks Irv, u are a great help in this--i think i have a final two
> questions for you, what exactly do u mean by "pointer" (if u have not
> noticed, i'm very new at this)? And where can i find Judith's IDE? I
> searched for it, but cannot find it.

If you read in a list of "moves", and save them in a sequence, 
you might have a sequence like:
{ {11,15},{15,20},{20,22},{22,24} }  

where 11 is the first source location, and 15 the first destination, 
and so on. Let's say you name this sequence "move".

To point to which move you are currently interested in, you need to 
declare an integer variable: call it anything you want. For example:

integer current

current = 1

now,  to refer to the first move on the list of moves, you'd say:
move[current] -- which is the same as saying move[1].
or {11,15}

The next move on the list would be move[2], so, 

current += 1 -- now current holds the value 2
move[current] -- same as move[2], which is:
{15,20}

So, you use the pointer into the list of moves to select the move 
you're interested in, and send that move to your routine which 
handles ..erm... moves.

You can get Judith's IDE from RDS' Recent Contributions page, or directly from
http://www2.txcyber.com/~camping/judith.html
Be sure you have the correct version of Win32Lib to go with that.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

8. Re: Help with coding

On Thursday 26 July 2001 11:16, Travis Weddle wrote:
>
>
> Irv--ok, instead of using the fn = open("moves.txt", "r") to open a file
> with moves in it, how would i use the Open command in the file menu to
> open a file, so i won't have to change coding for each file that i want
> to view?
>

In the editor, click on your File/Open menu selection, and enter
in the code box that pops up:

object fname
fname = getOpenFileName(Window1,
            "C:\\Bus\\*.edb",                     -- default path & extension
            {"Euphoria database","*.edb"}) -- file select options

if length(fname) > 0 then -- a file was selected
 -- put your file open code here
else -- no file was selected (cancelled)
 -- do whatever is appropriate
end if

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu