|
-
Apr 16th, 2010, 01:00 AM
#1
Thread Starter
Addicted Member
evaluating multiple possibilities
Question,
I am making a checkers program and I am in the phase of starting to evaluate jumps. This is what I currently have so far and allow me to fill you in a bit before you look at the code. Checker pieces are white/green. Each checker is created as a label at runtime and in the tag property a struct is held that possesses all of the information reguarding current and previous checker state.
The problem I am having is that as this sub runs each opposing checker is evaluated for jump capabilites which is all fine and dandy. It is even alright that currently if a jump is executed that the same side will continue to evaluate through the sub looking for additional jumps and if they are found they will be made because that is how it is currently coded. What I am trying to do is find a way to evaluate each piece that can jump. So if checker1 can only make one jump and checker2 can make a triple jump checker2 needs to be the guy making the jump and I honestly don't know how do start that. I am forseeing global vars being created to hold information or even a structure and taking the one that changes the most. If two checkers can only make 1 jump then I will rand the one that gets to jump (not looking to win any awards for AI here). Anyhow, any suggestions on how to start this, at least saving the information throughout the sub even if it is called recursively?
Thanks a lot if you can help.
Code:
Dim a As String = frmBoard.jumper
'split the checkers into two arrays.
For i = 0 To 23
Dim testChecker As Label
testChecker = frmBoard.checkersArray(i)
Dim testTag As frmBoard.structChip = CType(testChecker.Tag, frmBoard.structChip)
If testTag.chipColor = "white" Then
white(count) = testChecker
count += 1
End If
Next
count = 0
For i = 0 To 23
Dim testChecker As Label
testChecker = frmBoard.checkersArray(i)
Dim testTag As frmBoard.structChip = CType(testChecker.Tag, frmBoard.structChip)
If testTag.chipColor = "green" Then
green(count) = testChecker
count += 1
End If
Next
count = 0
'chip color
If tag.chipColor = "green" Then
'check for top or bottom
If tag.boardPosition = "bottom" Then
'loop white checkers
For i = 0 To 11
whiteTag = CType(white(i).Tag, frmBoard.structChip)
Dim wchip As String
wchip = whiteTag.name
'loop green checkers
For j = 0 To 11
greenTag = CType(green(j).Tag, frmBoard.structChip)
Dim gchip As String
gchip = greenTag.name
'determine king status
If whiteTag.kingStatus = False Then
'white checker position - 7
If whiteTag.currentTileLoc = greenTag.currentTileLoc - 7 Then
'test for opposite side
For k = 0 To 23
Dim checkerTest As Label = frmBoard.checkersArray(k)
Dim testTag As frmBoard.structChip = CType(checkerTest.Tag, frmBoard.structChip)
If testTag.currentTileLoc = greenTag.currentTileLoc + 7 Then
goJump = False
Exit For
Else
goJump = True
End If
Next
'evaluate the edge of the board
If greenTag.currentTileLoc = 2 Or greenTag.currentTileLoc = 3 Or greenTag.currentTileLoc = 4 _
Or greenTag.currentTileLoc = 5 Or greenTag.currentTileLoc = 6 Or greenTag.currentTileLoc = 7 _
Or greenTag.currentTileLoc = 1 Or greenTag.currentTileLoc = 8 _
Or greenTag.currentTileLoc = 9 Or greenTag.currentTileLoc = 16 _
Or greenTag.currentTileLoc = 17 Or greenTag.currentTileLoc = 24 _
Or greenTag.currentTileLoc = 25 Or greenTag.currentTileLoc = 32 _
Or greenTag.currentTileLoc = 33 Or greenTag.currentTileLoc = 40 _
Or greenTag.currentTileLoc = 41 Or greenTag.currentTileLoc = 48 _
Or greenTag.currentTileLoc = 49 Or greenTag.currentTileLoc = 56 _
Or greenTag.currentTileLoc = 57 Or greenTag.currentTileLoc = 64 _
Or greenTag.currentTileLoc = 58 Or greenTag.currentTileLoc = 59 Or greenTag.currentTileLoc = 60 _
Or greenTag.currentTileLoc = 61 Or greenTag.currentTileLoc = 62 Or greenTag.currentTileLoc = 63 Then
goJump = False
Else
'execute jump on - 7
If goJump = True Then
With whiteTag
.previousTileLoc = .currentTileLoc
.prevX = .currX
.prevY = .currY
.currentTileLoc = greenTag.currentTileLoc + 7
detTileCords(greenTag.currentTileLoc + 7, x, y)
.currX = x
.currY = y
.undo = True
End With
white(i).Tag = whiteTag
white(i).Location = New Point(x, y)
If whiteTag.currentTileLoc >= 57 Then
whiteTag.kingStatus = True
white(i).Image = Image.FromFile(whiteTag.kingImage)
white(i).Tag = whiteTag
End If
'update jumped checker
With greenTag
.jumped = True
.undo = True
.previousTileLoc = .currentTileLoc
.prevX = .prevX
.prevY = .currY
.currentTileLoc = Nothing
.currX = Nothing
.currY = Nothing
End With
green(j).Tag = greenTag
green(j).Visible = False
green(j).SendToBack()
frmBoard.jumper = white(i).Name
'ensure that all checkers have been looped through
If j < 11 And i < 11 Then
jumpAvailable(checkers)
End If
End If
End If
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Apr 16th, 2010, 01:16 AM
#2
Re: evaluating multiple possibilities
You should have a class that represents the possible moves a piece can make. That class would basically represent a tree, where each node is a square and each link to another node is a jump. There would be zero to four links from each node. That class would have a longest path and the piece with the longest longest path would be the one to move, following the longest path it can. Obviously you'd need other criteria to break a tie between two equally long paths.
-
Apr 16th, 2010, 01:20 AM
#3
Thread Starter
Addicted Member
Re: evaluating multiple possibilities
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Apr 16th, 2010, 01:21 AM
#4
Thread Starter
Addicted Member
Re: evaluating multiple possibilities
sorry rusty on data structures
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Apr 16th, 2010, 01:30 AM
#5
Re: evaluating multiple possibilities
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|