-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
can you post what you have so far so?
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
i didnt do anything......was just playing with but didnt get anywhere...:(
-
1 Attachment(s)
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
Okay here it is , I just mirrored the defensive logic and added a couple of if then's to round out the logic. I beat it once ( I got lucky) so it's not unbeatable, but it's a great opponent.
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
thnx alot great programming..........but again i would like u to add some comments so i can fully understand the coding.......thnx
this bit plz
Code:
'set O Defensive
Dim bitGroup(0 To 4) As Long
x = 0
i = 0
tmp = HighBit
If UBound(Os, 2) = 0 Then GoTo Defense
If Os(max, 1) > Xs(max, 1) Then GoTo Defense
Offense:
'construct bit image
Do While tmp
If (Os(bmask, 1) And tmp) > 0 Then
If (Os(bits, 1) And tmp) > 0 Then
bitGroup(i) = x + 1 '
i = i + 1
Else
bitGroup(i) = -(x + 1)
i = i + 1
End If
End If
x = x + 1
tmp = Int(tmp / 2)
Loop
'check for adjacency
For i = 0 To 3
If (Sgn(bitGroup(i)) <> Sgn(bitGroup(i + 1))) Then
If bitGroup(i) > 0 Then
x = bitGroup(i) - 1
Else
x = bitGroup(i + 1) - 1
End If
End If
Next
y = (Os(Cy, 1) + (x Mod 5)) * 19 + (Os(Cx, 1) + Int(x / 5))
'click it
Label1_Click y
Exit Sub
Defense:
'construct bit image
Do While tmp
If (Xs(bmask, 1) And tmp) > 0 Then
If (Xs(bits, 1) And tmp) > 0 Then
bitGroup(i) = x + 1 '
i = i + 1
Else
bitGroup(i) = -(x + 1)
i = i + 1
End If
End If
x = x + 1
tmp = Int(tmp / 2)
Loop
'check for adjacency
For i = 0 To 3
If (Sgn(bitGroup(i)) <> Sgn(bitGroup(i + 1))) Then
If bitGroup(i) > 0 Then
x = bitGroup(i) - 1
Else
x = bitGroup(i + 1) - 1
End If
End If
Next
y = (Xs(Cy, 1) + (x Mod 5)) * 19 + (Xs(Cx, 1) + Int(x / 5))
'click it
Label1_Click y
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
Code:
'set up necessary variables
Dim bitGroup(0 To 4) As Long
x = 0
i = 0
tmp = HighBit
' If first move go for a block
If UBound(Os, 2) = 0 Then GoTo Defense
'we Previously sorted moves by most winnable (least moves to win) to least winnable
'If defense has advantage choose defense
If Os(max, 1) > Xs(max, 1) Then GoTo Defense
Offense:
'construct bit image
'convert 5X5 array to 1X5 for analysis
Do While tmp
If (Os(bmask, 1) And tmp) > 0 Then
If (Os(bits, 1) And tmp) > 0 Then
bitGroup(i) = x + 1 '
i = i + 1
Else
bitGroup(i) = -(x + 1)
i = i + 1
End If
End If
x = x + 1
tmp = Int(tmp / 2)
Loop
'place new piece adjacent to existing
'check for adjacency
For i = 0 To 3
If (Sgn(bitGroup(i)) <> Sgn(bitGroup(i + 1))) Then
If bitGroup(i) > 0 Then
x = bitGroup(i) - 1
Else
x = bitGroup(i + 1) - 1
End If
End If
Next
'convert move to cartesian coordinat
y = (Os(Cy, 1) + (x Mod 5)) * 19 + (Os(Cx, 1) + Int(x / 5))
'click it
Label1_Click y
Exit Sub
'repeat same logic for defense
Defense:
'construct bit image
Do While tmp
If (Xs(bmask, 1) And tmp) > 0 Then
If (Xs(bits, 1) And tmp) > 0 Then
bitGroup(i) = x + 1 '
i = i + 1
Else
bitGroup(i) = -(x + 1)
i = i + 1
End If
End If
x = x + 1
tmp = Int(tmp / 2)
Loop
'check for adjacency
For i = 0 To 3
If (Sgn(bitGroup(i)) <> Sgn(bitGroup(i + 1))) Then
If bitGroup(i) > 0 Then
x = bitGroup(i) - 1
Else
x = bitGroup(i + 1) - 1
End If
End If
Next
y = (Xs(Cy, 1) + (x Mod 5)) * 19 + (Xs(Cx, 1) + Int(x / 5))
'click it
Label1_Click y
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
any way to make my forms look fancy or something like that?
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
You can use Pictures in your backgrounds and make your buttons graphical. Add a logo somewhere.
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
i have used a picture as a background and used an icon for project...how to make my buttons fancy.........
-
1 Attachment(s)
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
Welcome to Fancy Buttons Ltd.
In a project - add a UserControl
in the Usercontrol Code add this code:
Code:
'Property Variables:
Dim m_MaskPicture As Picture
Dim m_Picture As Picture
Dim m_DownPicture As Picture
Dim m_MaskDownPicture As Picture
'Event Declarations:
Public Event Click()
Private Sub UserControl_Click()
RaiseEvent Click
End Sub
Private Sub UserControl_Initialize()
With UserControl
.BackStyle = 0
.MaskColor = 0
Set m_MaskPicture = LoadPicture(App.Path & "\ButtonMask.bmp")
Set .MaskPicture = m_MaskPicture
Set m_Picture = LoadPicture(App.Path & "\ButtonUp.bmp")
Set .Picture = m_Picture
Set m_DownPicture = LoadPicture(App.Path & "\ButtonDn.bmp")
Set m_MaskDownPicture = LoadPicture(App.Path & "\ButtonDnMask.bmp")
End With
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set UserControl.Picture = m_DownPicture
Set UserControl.MaskPicture = m_MaskDownPicture
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set UserControl.Picture = m_Picture
Set UserControl.MaskPicture = m_MaskPicture
End Sub
Now you'll need some button images - see attachment below.
Pay special attention on how I created the 3D illusion.
to use the control close it's design form and it will appear on the toolbar. Drag it into your project form. It has only 1 event - "Click" and you can put your code in there. start with
Code:
Private Sub UserControl1_Click()
MsgBox "click"
End Sub
for testing purposes.
Wow that's all Rob? Yup that's about it. Now go forth and improvise.
Post Edited I've added a round button - just change the file name.
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
hello mate..!
i am a bit confuse in gnome sorting part..how is it working in my program and how is it swapping around.
i found explaination on internet
It simply moves forward until something is out of order. When one is found, it swaps the element back until it is in its place. Then, it continues traversing from that point
could u plz explain it to me.......
thnx
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
Sure - I'm going to quote myself from a previous thread where I described the workings of a gnome sort:
Quote:
It's based on an analogy of a garden gnome who wants to sort flower pots sitting in a line from small to big.
He goes to the first two , if the smaller one is first, he's ok with it so he steps to his right. If the next two are not in order he switches them and takes 1 step back and starts again. When he reaches the end all the flower pots are sorted.
The key to the process is not the switch but the step back - all sorting in place has some form of recursion, the beauty of a gnome sort over a bubble sort ( another popular sort in place algorithm) is that it doesn't have to start at the beginning all the time - just 1 step back. Otherwise they're very similar.
Hope that helps.
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
i got that.....now im my program when i put two Xs close to each other, right? how does it know that "O" need to be put next to it so that X cant win. the sorting X and sorting O part of the coding....is it doing that?
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
When the winning (or loosing ) pattern has been identified (by sorting) the routine converts that pattern from a 5X5 matrix (2 dimensional) to a 1X5 matrix (one dimensional) to check for adjacency. it then puts the O next to an X to block that pattern from becoming winnable. Or is it has the advantage it does the same to increase the winnability (new word, I created it) of the pattern. Or to win if it's the last piece.
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
thnx alot...
and one more thing about patterns which are defind in loud routine...how were they made................u mentioned excel i think.......how?
-
1 Attachment(s)
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
key functions are BIN2DEC and DEC2HEX
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
-
1 Attachment(s)
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
hello mate......this AI player have done my heading could u plz have a look at it..........when player 1 wins it gives the same error that was giving before.....
i added nowinner as boolean .set it true when game start but when player 1 wins it gives an error....but when computer wins it doesnt.....i think the problem is when resetting the grid nowinner is not setting to true......plz have a look
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
I corrected all this once in a previous post, but you had a button to reset the game then.
You can't reset from the check routine. It creates a circular logic. To correct first rem all the stuff I remmed in this part of the check routine:
Code:
Winner:
NoWinner = False
'==========================Player 1==================================
If turn = "X" Then
MsgBox " Player 1 wins ", vbInformation, "Gomoku"
player1_score = player1_score + 1
lbl_player1score.Caption = player1_score
' For index = 0 To 360
' Label1(index).Caption = ""
' Next index
End If
'==========================Player 2==================================
If turn = "O" Then
MsgBox " Player 2 wins ", vbInformation, "Gomoku"
player2_score = player2_score + 1
lbl_player2score.Caption = player2_score
'
' For index = 0 To 360
' Label1(index).Caption = ""
' Next index
'
End If
' player1 = True
' NoWinner = True
End Sub
Next Add this code to the bottom of the Label1_Click routine, right before the End Sub:
Code:
Skip:
If NoWinner Then Exit Sub
Dim i As Integer
player1 = True
NoWinner = True
For i = 0 To 360
Label1(i).Caption = ""
Next
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
so there isn't any way then? i have to keep it like this then
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
Sure just make the changes i outlined in the post above and it should do what you want.
-
Re: seeking help with a project.......!, Gomoku or 5 in a row Game
hello can i delete this thread i have started?