pin tic tac toe 4x4x4

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

Moderator: anthonio

pin tic tac toe 4x4x4

Berichtdoor bluatigro » zo dec 04, 2016 5:17 pm

error :
p() index buiten array ???

Code: Selecteer alles

global kl$
dim p(4*4*4)
kl$ = ".XO"

call bord
call zet 1 , 3 , 1
call bord

end

function q(x,y,z)
  q=x+y*4+z*16
end function

sub bord
  print "+----+----+----+----+"
  for a = 0 to 3
    print "|" ;
    for b = 0 to 3
      for c = 0 to 3
        print mid$( kl$ , p(q(a,b,c))+1 , 1 ) ;
      next c
      print "|" ;
    next b
    print
  next a
  print "+----+----+----+----+"
end sub

sub zet x , z , who
  y = 0
  while p(q(x,y,z)) = 0
    y = y + 1
  wend
  p(q(x,y,z)) = who
end sub

sub unzet x , z
  y = 0
  while p(q(x,y,z)) = 0 and y < 4
    y = y + 1
  wend
  p(q(x,y,z)) = 0
end sub

function dice()
  dice = int( rnd * 4 )
end function

sub rando byref x , byref z
  x = dice()
  z = dice()
  while p(q(x,0,z))
    x = dice()
    z = dice()
  wend
end sub

sub human who
[opnieuw]
  print "   1234"
  print "  qwer"
  print " asdf"
  print "zxcv"
  input "Move = " ; in$
  if len( in$ ) <> 1 then goto [opnieuw]
  if instr( "1234qwerasdfzxcv" , in$ ) = 0 then goto [opnieuw]
  t = instr( "1234qwerasdfzxcv" , in$ )
  z = int( ( t - 1 ) / 4 )
  x = ( t - 1 ) and 3
  if p(q(x,0,z)) then
    print "On a upper empty pin please !!"
    input "[ pres return ]" ; a$
    goto [opnieuw]
  end if
  call zet x , z , who
end sub

function row()
  uit = 0
  for a = 0 to 3
    for b = 0 to 3
      if p(q(a,b,0))=p(q(a,b,1)) _
      and p(q(a,b,1))=p(q(a,b,2)) _
      and p(q(a,b,2))=p(q(a,b,3)) _
      and p(q(a,b,0)) then uit = p(q(a,b,0))
      if p(q(a,0,b))=p(q(a,1,b)) _
      and p(q(a,1,b))=p(q(a,2,b)) _
      and p(q(a,2,b))=p(q(a,3,b)) _
      and p(q(a,0,b)) then uit = p(q(a,0,b))
      if p(q(0,a,b))=p(q(1,a,b)) _
      and p(q(1,a,b))=p(q(2,a,b)) _
      and p(q(2,a,b))=p(q(3,a,b)) _
      and p(q(0,a,b)) then uit = p(q(0,a,b))
    next b
    if p(q(a,0,0))=p(q(a,1,1)) _
    and p(q(a,1,1))=p(q(a,2,2)) _
    and p(q(a,2,2))=p(q(a,3,3)) _
    and p(q(a,0,0)) then uit = p(q(a,0,0))
    if p(q(0,a,0))=p(q(1,a,1)) _
    and p(q(1,a,1))=p(q(2,a,2)) _
    and p(q(2,a,2))=p(q(3,a,3)) _
    and p(q(0,a,0)) then uit = p(q(0,a,0))
    if p(q(0,0,a))=p(q(1,1,a)) _
    and p(q(1,1,a))=p(q(2,2,a)) _
    and p(q(2,2,a))=p(q(3,3,a)) _
    and p(q(0,0,a)) then uit = p(q(0,0,a))
    if p(q(a,0,3))=p(q(a,1,2)) _
    and p(q(a,1,2))=p(q(a,2,1)) _
    and p(q(a,2,1))=p(q(a,3,0)) _
    and p(q(a,0,0)) then uit = p(q(a,0,0))
    if p(q(0,a,3))=p(q(1,a,2)) _
    and p(q(1,a,2))=p(q(2,a,1)) _
    and p(q(2,a,1))=p(q(3,a,0)) _
    and p(q(a,0,3)) then uit = p(q(0,a,3))
    if p(q(0,3,a))=p(q(1,2,a)) _
    and p(q(1,2,a))=p(q(2,1,a)) _
    and p(q(2,1,a))=p(q(3,0,a)) _
    and p(q(0,3,a)) then uit = p(q(0,3,a))
  next a
  if p(q(0,0,0))=p(q(1,1,1)) _
  and p(q(1,1,1))=p(q(2,2,2)) _
  and p(q(2,2,2))=p(q(3,3,3)) _
  and p(q(0,0,0)) then uit = p(q(0,0,0))
  if p(q(3,3,0))=p(q(2,2,1)) _
  and p(q(2,2,1))=p(q(1,1,2)) _
  and p(q(1,1,2))=p(q(0,0,3)) _
  and p(q(0,0,3)) then uit = p(q(0,0,3))
  if p(q(0,3,0))=p(q(1,2,1)) _
  and p(q(1,2,1))=p(q(2,1,2)) _
  and p(q(2,1,2))=p(q(3,0,3)) _
  and p(q(0,3,0)) then uit = p(q(0,3,0))
  if p(q(0,0,3))=p(q(1,1,2)) _
  and p(q(1,1,2))=p(q(2,2,1)) _
  and p(q(2,2,1))=p(q(3,3,0)) _
  and p(q(0,0,3)) then uit = p(q(0,0,3))
  row = uit
end function

sub ai who
  for x = 0 to 3
    for z = 0 to 3
      call zet x , z , who
      if row() then exit sub
    next z
  next x
  for x = 0 to 3
    for z = 0 to 3
      call zet x , z , 3 - who
      if row() then
        call unzet x , z
        call zet x , z , who
        exit sub
      else
        call unzet x , y
      end if
    next z
  next x
  call rando x , z
  call zet x , z , who
end sub

function vol()
  bool = 1
  for a = 0 to 3
    for b = 0 to 3
      if p(q(a,0,b)) = 0 then bool = 0
    next b
  next a
  vol = bool
end function

bluatigro
 
Berichten: 303
Geregistreerd: za sep 27, 2008 6:01 pm

Re: pin tic tac toe 4x4x4

Berichtdoor bluatigro » zo dec 04, 2016 6:26 pm

error :
spel 5 rando - rando loop vast

Code: Selecteer alles

global kl$
dim p(4*4*4)
kl$ = ".XO"

[keuze]
print "Welkome by PinTicTacToe 4x4x4 ."
print "A game by bluatigro ."
print "Object of the game :"
print "move your peece in a 4 row , colom or diagonal ."
print
print " 1 : human - rando ."
print " 2 : rando - human ."
print " 3 : human - the ai ."
print " 4 : the ai - human ."
print " 5 : rando - rando ."
print " 6 : the ai - the ai ."
input "Choise : " ; in$
if len( in$ ) <> 1 _
or val( in$ ) < 1  _
or val( in$ ) > 6 then goto [keuze]
player = 1
while not( row() ) and not( vol() )
  select case val( in$ )
    case 1
      if player = 1 then
        call human player
      else
        call rando x , z
        call zet x , z , player
      end if
    case 2
      if player = 2 then
        call human player
      else
        call rando x , z
        call zet x , z , player
      end if
    case 3
      if player = 1 then
        call human player
      else
        call ai player
      end if
    case 4
      if player = 2 then
        call human player
      else
        call ai player
      end if
    case 5
      call rando x , z
      call zet x , z , player
    case else
      call ai player
  end select
  player = 3 - player
wend
print "[ game over ]"
if row() = 0 then
  print "Its a tie ."
else
  select case val( in$ )
    case 1
      if player = 1 then
        print "You have won from rando ."
      else
        print "You have lost from rando ."
      end if
    case 2
      if player = 2 then
        print "You have won from rando ."
      else
        print "You have lost from rando ."
      end if
    case 3
      if player = 1 then
        print "You have won from the ai ."
      else
        print "You have lost from the ai ."
      end if
    case 4
      if player = 2 then
        print "You have won from the ai ."
      else
        print "You have lost from the ai ."
      end if
    case 5
      print "Rando " ; player ; " has won ."
    case else
      print "Ai " ; player ; " has won ."
  end select
end if

print "[ end of program ]"

end

function q(x,y,z)
  q=x+y*4+z*16
end function

sub bord
  print "+----+----+----+----+"
  for a = 0 to 3
    print "|" ;
    for b = 0 to 3
      for c = 0 to 3
        print mid$( kl$ , p(q(a,b,c))+1 , 1 ) ;
      next c
      print "|" ;
    next b
    print
  next a
  print "+----+----+----+----+"
end sub

sub zet x , z , who
  y = 0
  while p(q(x,y,z)) = 0 and y < 3
    y = y + 1
  wend
  p(q(x,y,z)) = who
end sub

sub unzet x , z
  y = 0
  while p(q(x,y,z)) = 0 and y < 3
    y = y + 1
  wend
  p(q(x,y,z)) = 0
end sub

function dice()
  dice = int( rnd * 4 )
end function

sub rando byref x , byref z
  x = dice()
  z = dice()
  while p(q(x,0,z))
    x = dice()
    z = dice()
  wend
end sub

sub human who
[opnieuw]
  call bord
  print "+----+"
  print "|1234|"
  print "|qwer|"
  print "|asdf|"
  print "|zxcv|"
  print "+----+"
  input "Move = " ; in$
  if len( in$ ) <> 1 then goto [opnieuw]
  if instr( "1234qwerasdfzxcv" , in$ ) = 0 then goto [opnieuw]
  t = instr( "1234qwerasdfzxcv" , in$ )
  z = int( ( t - 1 ) / 4 )
  x = ( t - 1 ) and 3
  if p(q(x,0,z)) then
    print "On a upper empty pin please !!"
    input "[ pres return ]" ; a$
    goto [opnieuw]
  end if
  call zet x , z , who
end sub

function row()
  uit = 0
  for a = 0 to 3
    for b = 0 to 3
      if p(q(a,b,0))=p(q(a,b,1)) _
      and p(q(a,b,1))=p(q(a,b,2)) _
      and p(q(a,b,2))=p(q(a,b,3)) _
      and p(q(a,b,0)) then uit = p(q(a,b,0))
      if p(q(a,0,b))=p(q(a,1,b)) _
      and p(q(a,1,b))=p(q(a,2,b)) _
      and p(q(a,2,b))=p(q(a,3,b)) _
      and p(q(a,0,b)) then uit = p(q(a,0,b))
      if p(q(0,a,b))=p(q(1,a,b)) _
      and p(q(1,a,b))=p(q(2,a,b)) _
      and p(q(2,a,b))=p(q(3,a,b)) _
      and p(q(0,a,b)) then uit = p(q(0,a,b))
    next b
    if p(q(a,0,0))=p(q(a,1,1)) _
    and p(q(a,1,1))=p(q(a,2,2)) _
    and p(q(a,2,2))=p(q(a,3,3)) _
    and p(q(a,0,0)) then uit = p(q(a,0,0))
    if p(q(0,a,0))=p(q(1,a,1)) _
    and p(q(1,a,1))=p(q(2,a,2)) _
    and p(q(2,a,2))=p(q(3,a,3)) _
    and p(q(0,a,0)) then uit = p(q(0,a,0))
    if p(q(0,0,a))=p(q(1,1,a)) _
    and p(q(1,1,a))=p(q(2,2,a)) _
    and p(q(2,2,a))=p(q(3,3,a)) _
    and p(q(0,0,a)) then uit = p(q(0,0,a))
    if p(q(a,0,3))=p(q(a,1,2)) _
    and p(q(a,1,2))=p(q(a,2,1)) _
    and p(q(a,2,1))=p(q(a,3,0)) _
    and p(q(a,0,0)) then uit = p(q(a,0,0))
    if p(q(0,a,3))=p(q(1,a,2)) _
    and p(q(1,a,2))=p(q(2,a,1)) _
    and p(q(2,a,1))=p(q(3,a,0)) _
    and p(q(a,0,3)) then uit = p(q(0,a,3))
    if p(q(0,3,a))=p(q(1,2,a)) _
    and p(q(1,2,a))=p(q(2,1,a)) _
    and p(q(2,1,a))=p(q(3,0,a)) _
    and p(q(0,3,a)) then uit = p(q(0,3,a))
  next a
  if p(q(0,0,0))=p(q(1,1,1)) _
  and p(q(1,1,1))=p(q(2,2,2)) _
  and p(q(2,2,2))=p(q(3,3,3)) _
  and p(q(0,0,0)) then uit = p(q(0,0,0))
  if p(q(3,3,0))=p(q(2,2,1)) _
  and p(q(2,2,1))=p(q(1,1,2)) _
  and p(q(1,1,2))=p(q(0,0,3)) _
  and p(q(0,0,3)) then uit = p(q(0,0,3))
  if p(q(0,3,0))=p(q(1,2,1)) _
  and p(q(1,2,1))=p(q(2,1,2)) _
  and p(q(2,1,2))=p(q(3,0,3)) _
  and p(q(0,3,0)) then uit = p(q(0,3,0))
  if p(q(0,0,3))=p(q(1,1,2)) _
  and p(q(1,1,2))=p(q(2,2,1)) _
  and p(q(2,2,1))=p(q(3,3,0)) _
  and p(q(0,0,3)) then uit = p(q(0,0,3))
  row = uit
end function

sub ai who
  for x = 0 to 3
    for z = 0 to 3
      call zet x , z , who
      if row() then exit sub
    next z
  next x
  for x = 0 to 3
    for z = 0 to 3
      call zet x , z , 3 - who
      if row() then
        call unzet x , z
        call zet x , z , who
        exit sub
      else
        call unzet x , y
      end if
    next z
  next x
  call rando x , z
  call zet x , z , who
end sub

function vol()
  bool = 1
  for a = 0 to 3
    for b = 0 to 3
      if p(q(a,0,b)) = 0 then bool = 0
    next b
  next a
  vol = bool
end function

bluatigro
 
Berichten: 303
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