bord spel

Vragen en suggesties over het programmeren van spelletjes, sprites en dergelijke in Liberty BASIC

Moderator: anthonio

bord spel

Berichtdoor bluatigro » di jan 31, 2012 1:14 pm

regels :
zet je steen diagonaal naar boven
of sla een computer-steen door er diagonaal over te sprigen
doel : sla 7 stenen [ nog niet actief ]

de AI kijk als volgt :\
-1 veilige slag
-2 slag
-3 veilige zet
-4 wilekuerige zet

error :
de AI ziet n veilige zet soms niet als veilig
Code: Selecteer alles
dim p( 100 )
for y = 0 to 9
  for x = 0 to 9
    read veld
    p( index( x , y ) ) = veld
  next x
next y
data 0,0,0,0,0,0,0,0,0,0
data 0,1,0,1,0,1,0,1,0,0
data 0,0,1,0,1,0,1,0,1,0
data 0,1,0,1,0,1,0,1,0,0
data 0,0,4,0,4,0,4,0,4,0
data 0,4,0,4,0,4,0,4,0,0
data 0,0,2,0,2,0,2,0,2,0
data 0,2,0,2,0,2,0,2,0,0
data 0,0,2,0,2,0,2,0,2,0
data 0,0,0,0,0,0,0,0,0,0
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , empty , human , comp , mode , wie
winx = WindowWidth
winy = WindowHeight
empty = 4
human = 2
comp = 1
nomainwin
textbox #m.txt , 100 , winy - 150 , winx/2 - 200 , 100
button #m.btnOK , "OK" , [ok] , ul , winx/2 - 100 , winy - 150 , 100 , 100
''menu #m , "mode" , "automatic" , [auto] , "You play" , [you]
open "checkers" for graphics as #m
  #m "trapclose [quit]"
  #m.txt "!font Ariel 50 bold"
  #m.txt "!setfocus"
  #m.btnOK "!font Ariel 50 bold"
  call drawbord
wait
sub drawbord
  #m "cls"
  #m "font Ariel 20 bold"
  for x = 0 to 9
    for y = 0 to 9
      q = p( index( x , y ) )
      #m "backcolor white"
      #m "goto " ; x * winx / 10 + 5 ; " " ; y * winy / 12 + 30
      #m "down"
      #m "\" ; index( x , y )
      #m "up"
      select case q
        case 0
          #m "backcolor black"
          #m "goto " ; x * winx / 10 ; " " ; y * winy / 12
          #m "down"
          #m "boxfilled " ; ( x + 1 ) * winx / 10 ; " " ; ( y + 1 ) * winy / 12
          #m "up"
        case 1
          #m "backcolor cyan"
          #m "goto " ; ( x + .5 ) * winx / 10 ; " " ; ( y + .5 ) * winy / 12
          #m "down"
          #m "circlefilled 30"
          #m "up"
        case 2
          #m "backcolor pink"
          #m "goto " ; ( x + .5 ) * winx / 10 ; " " ; ( y + .5 ) * winy / 12
          #m "down"
          #m "circlefilled 30"
          #m "up"
        case else
      end select
    next y
  next x
end sub
''[auto]
''  mode = 0
''  timer 1000 , [tmr]
''  wie = 1
''wait
''[you]
''  mode = 1
''  timer 0
''wait
''[tmr]
''  wie = 0-wie
''  call computer wie
''wait
[ok]
''if mode then
  #m.txt "!contents? move$"
  a = val( word$( move$ , 1 ) )
  b = val( word$( move$ , 2 ) )
  #m.txt ""
  #m.txt "!setfocus"
  gezet = 0
  if a<11 or a>88 or b<11 or b>88 then
    notice chr$( 13 ) _
         + "To low or high number ."
  else
    if p( a ) <> human then
      notice chr$( 13 ) _
           + "Ilegal move :" + chr$( 13 ) _
           + "not your stone !!"
    else
      if p( b ) <> empty then
        notice chr$( 13 ) _
             + "Ilegal move :" + chr$( 13 ) _
             + "move to a empty place !!"
      else
        if a - b = 9 or a - b = 11 _
        or a - b = 18 or a - b = 22 _
        or a - b = -18 or a - b = -22 then
          if a - b = 18 or a - b = 22 _
          or a - b = -18 or a - b = -22 then
            if p( ( a + b ) / 2 ) = comp then
              p( a ) = empty
              p( ( a + b ) / 2 ) = empty
              p( b ) = human
              gezet = 1
              humanpoints = humanpoints + 1
            else
              notice chr$( 13 ) + "Ilegal hit !!"
            end if
          else
            p( a ) = empty
            p( b ) = human
            gezet = 1
          end if
        else
          notice chr$( 13 ) + "Iligal move !!"
        end if
      end if
    end if
  end if
  call drawbord
  if gezet then call computer 1
''end if
wait
sub computer no
  van$ = ""
  naar$ = ""
  s$ = ""
  text$ = chr$( 13 ) + "I m looking for hits ." + chr$( 13 )
  ''look for legal hits
  hitfount = 0
  savefount = 0
  for i = 0 to 100
    if p( i ) = comp then
      if i < 100 - 22 then
        if p( i + 9*no ) = human and p( i + 18*no ) = empty then
          van$ = van$ + str$( i ) + " "
          naar$ = naar$ + str$( i + 18*no ) + " "
          text$ = text$ + str$( i ) + " to " + str$( i + 18*no )
          gosub [ismovesave]
          hitfount = 1
        end if
        if p( i + 11*no ) = human and p( i + 22*no ) = empty then
          van$ = van$ + str$( i ) + " "
          naar$ = naar$ + str$( i + 22*no ) + " "
          text$ = text$ + str$( i ) + " to " + str$( i + 11*no )
          gosub [ismovesave]
          hitfount = 1
        end if
      end if
      if i > 22 then
        if p( i - 9*no ) = human and p( i - 18*no ) = empty then
          van$ = van$ + str$( i ) + " "
          naar$ = naar$ + str$( i - 18*no ) + " "
          text$ = text$ + str$( i ) + " to " + str$( i - 18*no )
          gosub [ismovesave]
          hitfount = 1
        end if
        if p( i - 11*no ) = human and p( i - 22*no ) = empty then
          van$ = van$ + str$( i ) + " "
          naar$ = naar$ + str$( i - 22*no ) + " "
          text$ = text$ + str$( i ) + " to " + str$( i - 22*no )
          gosub [ismovesave]
          hitfount = 1
        end if
      end if
    end if
  next i
  if not( hitfount ) then
    text$ = text$ + chr$( 13 ) + "No hits fount . looking for moves ." + chr$( 13 )
    ''look for legal moves
    for i = 0 to 100
      ''look for computer stones
      if p( i ) = comp then
        ''look for empty target
        if p( i + 9*no ) = empty then
          van$ = van$ + str$( i ) + " "
          naar$ = naar$ + str$( i + 9 ) + " "
          text$ = text$ + str$( i ) + " to " + str$( i + 9*no )
          gosub [ismovesave]
        end if
        if p( i + 11*no ) = empty then
          van$ = van$ + str$( i ) + " "
          naar$ = naar$ + str$( i + 11*no ) + " "
          text$ = text$ + str$( i ) + " to " + str$( i + 11*no )
          gosub [ismovesave]
        end if
      end if
    next i
  end if
  ''howmany moves found
  q = 1
  while word$( van$ , q ) <> ""
    q = q + 1
  wend
  ''pick a move at random
  if savefount then
    while movenaar = 0 or savechoice = 0
      move = int( rnd( 0 ) * q )
      movevan = val( word$( van$ , move ) )
      movenaar = val( word$( naar$ , move ) )
      savechoice = val( word$( s$ , move ) )
    wend
  else
    while movenaar = 0
      move = int( rnd( 0 ) * q )
      movevan = val( word$( van$ , move ) )
      movenaar = val( word$( naar$ , move ) )
    wend
  end if
  text$ = text$ + chr$( 13 ) + "I do move : "
  text$ = text$ +  str$( movevan ) + " to " + str$( movenaar )
  p( movevan ) = empty
  p( movenaar ) = comp
  if abs(movenaar - movevan) = 18 or abs(movenaar - movevan) = 22 then
    p( ( movevan + movenaar ) / 2 ) = empty
    comppoints = comppoinst + 1
  end if
  if not( mode ) then notice text$
  call drawbord
  exit sub
  [ismovesave]
     if save( i , i + 9 * no ) then
       savefount = not( 0 )
       text$ = text$ + "  SAVE !!" + chr$( 13 )
       s$ = s$ + "1 "
     else
       text$ = text$ + chr$( 13 )
       s$ = s$ + "0 "
     end if
  return
end sub
function save( a , x )
  uit = not( 0 )
  select case x-a
    case 9
      if p( x + 9 ) = human then uit = 0
      if p( x + 11 ) = human and p( x - 11 ) = empty then uit = 0
      if p( x - 11 ) = human and p( x + 11 ) = empty then uit = 0
    case 11
      if p( x + 11 ) = human then uit = 0
      if p( x + 9 ) = human and p( x - 9 ) = empty then uit = 0
      if p( x - 9 ) = human and p( x + 9 ) = empty then uit = 0
    case else ''move is hit
      if p( x + 9 ) = human and p( x - 9 ) = empty then uit = 0
      if p( x - 9 ) = human and p( x + 9 ) = empty then uit = 0
      if p( x + 11 ) = human and p( x - 11 ) = empty then uit = 0
      if p( x - 11 ) = human and p( x + 11 ) = empty then uit = 0
  end select
  save = uit
end function
function index( x , y )
  index = x + y * 10
end function
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar Games

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron