My latest VB.NET program, to play the board game backgammon, is done (subject to fixes and further work!). It’s been through many, many iterations. I’m happy with the result despite more work needing to be put into improving game strategy. I’ll see. Here’s a video of a game.
And here is a sample of the code….
Module PlayFunctionsModule
Public Function AbleToPlay(ND As Integer) As Boolean
'
' See if there is any move that can be made with the current dice
'
If IIf(CurrentPlayer = Whois.human, HumanBlotCount, RobotBlotCount) > 0 Then
If AbleToPlayBlot(ND) Then Return vbTrue Else Return vbFalse
End If
If AbleToPlayNormal(ND) Then
Return vbTrue
End If
If InBearOffZone() And AbleToBearOff(ND) Then
Return vbTrue
End If
Return vbFalse
End Function
Public Function AbleToPlayBlot(ND As Integer) As Boolean
'
' See if there is a blot move that can be made with the current dice
'
Dim p, d As Integer
If IIf(CurrentPlayer = Whois.human, HumanBlotCount, RobotBlotCount) > 0 Then
For d = 1 To ND
p = Dice(d)
If PointOwner(p) = CurrentPlayer Or (PointValue(p) <= 1) Then
Return vbTrue
End If
Next
Return vbFalse
End If
Return vbFalse
End Function
Public Function AbleToPlayNormal(ND As Integer) As Boolean
'
' See if there is a normal move that can be made with the current dice
'
Dim p, pTO, d As Integer
For d = 1 To ND
For p = 1 To nLandingPoints
If PointOwner(p) = CurrentPlayer Then
pTO = p + Dice(d)
If pTO <= nLandingPoints Then
If (PointOwner(pTO) = CurrentPlayer) Or (PointValue(pTO) <= 1) Then
Return vbTrue
End If
End If
End If
Next
Next
Return vbFalse
End Function
End Module

Have your say! (No need for any ID!)