Advertisement
warriortimmy

AI Module

Mar 12th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.09 KB | None | 0 0
  1. =begin
  2.  
  3.   *** SCRIPT CREADO POR NEWOLD, FEBRERO-MARZO 2011, TRIPLE TRIAD 1.0 ***
  4.  
  5.   LA IA PARA LOS ENEMIGOS ESTÁ DEFINIDA EN EL SIGUIENTE MÓDULO
  6.  
  7. =end
  8.  
  9. module  Newold
  10. # ******************************************************************************
  11.   # Este módulo se encarga de manejar la IA de los enemigos
  12. # ******************************************************************************
  13.   module IA
  14.     # ---------------------------------------------------------------------------
  15.     def ia(maxsimulations)
  16.       # ---------------------------------------------------------------------
  17.       # Recopilar los datos para empezar las simulaciones
  18.       # ---------------------------------------------------------------------
  19.       boarddata = [Array.new(3),Array.new(3),Array.new(3)]
  20.       playerdata = []
  21.       enemydata = []
  22.       jugadas = []
  23.       for x in 0...3
  24.         for y in 0...3
  25.           data = @boarddeck[x][y]
  26.           if data != nil and data != -1
  27.             atk = data[2][3].dup
  28.             boarddata[x][y] = [data[2][5],atk,data[3]]
  29.           else
  30.             boarddata[x][y] = data
  31.           end
  32.         end
  33.       end
  34.       @playerdeck.each do |item|
  35.         atk = item[2][3].dup
  36.         playerdata.push([0,atk,item[3]])
  37.       end
  38.       @enemydeck.each do |item|
  39.         atk = item[2][3].dup
  40.         enemydata.push([1,atk,item[3]])
  41.       end
  42.       file = File.open('tempcardsdata', "wb")
  43.       Marshal.dump(boarddata, file)
  44.       Marshal.dump(playerdata, file)
  45.       Marshal.dump(enemydata, file)
  46.       file.close
  47.       #return
  48.       # ---------------------------------------------------------------------
  49.       # Ejecutar simulaciones
  50.       # ---------------------------------------------------------------------
  51.       real_move = nil
  52.       maxsimulation = 5
  53.       changeindex = maxsimulations / 5
  54.       changeindex = 1 if changeindex < 1
  55.       lastanimate = -1
  56.       @indexani = -1
  57.       for i in 0...maxsimulations
  58.         @frameglobal += 1
  59.         @frameglobal = 0 if @frameglobal >= 100
  60.         if @frameglobal % 3 == 0
  61.           animatetextaction
  62.           Graphics.update
  63.         end
  64.         if @frameglobal % 7 == 0
  65.           animateselector2
  66.           Graphics.update
  67.         end
  68.         turn = 1
  69.         chargedatasimulation
  70.         record_move = nil
  71.         cnt = 0
  72.         # ---------------------------------------------------
  73.         # Animar Deck
  74.         if i % changeindex == 0
  75.           @indexani += 1
  76.           @indexani = @enemydeck.size - 1 if @indexani >= @enemydeck.size
  77.           if lastanimate > -1
  78.             card = @enemydeck[lastanimate]
  79.             card[0].x -= 17
  80.             card[0].y -= 6
  81.             card[0].z = lastanimate
  82.           end
  83.           card = @enemydeck[@indexani]
  84.           lastanimate = @indexani
  85.           card[0].x += 17
  86.           card[0].y += 6
  87.           card[0].z = 10
  88.         end
  89.         # ---------------------------------------------------
  90.         simulation_cnt = 0
  91.         while boardnilsimulation?
  92.           if simulation_cnt >= maxsimulation
  93.             real_move = [record_move,cardsgainsimulation?]
  94.             if jugadas.size == 0
  95.               jugadas.push(real_move)
  96.             else
  97.               if cardsgainsimulation? > jugadas[0][1]
  98.                 jugadas = []
  99.                 jugadas.push(real_move)
  100.               elsif cardsgainsimulation? == jugadas[0][1]
  101.                 if !jugadas.include?(real_move)
  102.                   jugadas.push(real_move)
  103.                 end
  104.               end
  105.             end
  106.             break
  107.           end
  108.           simulation_cnt += 1
  109.           deck = (turn == 1 ? @data3 : @data2)
  110.           index = rand(deck.size)
  111.           casillasjugables = checkcasillasjugablessimulation
  112.           casilla = casillasjugables[rand(casillasjugables.size)]
  113.           @indexboardx = casilla[0]
  114.           @indexboardy = casilla[1]
  115.           card = deck[index].dup
  116.           deck.delete_at(index)
  117.           @data1[@indexboardx][@indexboardy] = card
  118.           if record_move == nil and turn = 1
  119.             record_move = [index,casilla]
  120.           end
  121.           checkplaysimulation(turn)
  122.           if turn == 1
  123.             turn = 0
  124.           else
  125.             turn = 1
  126.           end
  127.           cnt += 1
  128.           if cnt >= 10
  129.             break
  130.           end
  131.         end
  132.         real_move = [record_move,cardsgainsimulation?]
  133.         if jugadas.size == 0
  134.           jugadas.push(real_move)
  135.         else
  136.           if cardsgainsimulation? > jugadas[0][1]
  137.             jugadas = []
  138.             jugadas.push(real_move)
  139.           elsif cardsgainsimulation? == jugadas[0][1]
  140.             if !jugadas.include?(real_move)
  141.               jugadas.push(real_move)
  142.             end
  143.           end
  144.         end
  145.       end
  146.       # ---------------------------------------------------------------------
  147.       # Terminar simulación
  148.       # ---------------------------------------------------------------------
  149.       jugada = jugadas[rand(jugadas.size)]
  150.       bestjugada = nil
  151.       jugadas.each do |item|
  152.         if bestjugada == nil
  153.           bestjugada = item
  154.         else
  155.           currentcardatk = 0
  156.           id = item[0][0]
  157.           card = @enemydeck[id]
  158.           atk = card[2][3]
  159.           x = item[0][1][0]
  160.           y = item[0][1][1]
  161.           atk.each do |pow|
  162.             currentcardatk += pow
  163.           end
  164.           if @reglaelemental
  165.             if @boardelemental[x][y] != nil
  166.               if card[2][2] == @boardelemental[x][y]
  167.                 currentcardatk += 10
  168.               else
  169.                 currentcardatk -= 10
  170.               end
  171.             end
  172.           end
  173.           if (x == 0 and y == 0) or (x == 2 and y == 0) or
  174.              (x == 0 and y == 2) or (x == 2 and y == 2)
  175.             currentcardatk += 10
  176.           elsif (x == 1 and y == 0) or (x == 0 and y == 1) or
  177.              (x == 2 and y == 1) or (x == 1 and y == 2)
  178.             currentcardatk += 5
  179.           end
  180.           recordcardatk = 0
  181.           id = bestjugada[0][0]
  182.           card = @enemydeck[id]
  183.           atk = card[2][3]
  184.           x = bestjugada[0][1][0]
  185.           y = bestjugada[0][1][1]
  186.           atk.each do |pow|
  187.             recordcardatk += pow
  188.           end
  189.           if (x == 0 and y == 0) or (x == 2 and y == 0) or
  190.              (x == 0 and y == 2) or (x == 2 and y == 2)
  191.             recordcardatk += 10
  192.           elsif (x == 1 and y == 0) or (x == 0 and y == 1) or
  193.              (x == 2 and y == 1) or (x == 1 and y == 2)
  194.             recordcardatk += 5
  195.           end
  196.           if recordcardatk < currentcardatk
  197.             bestjugada = item
  198.           end
  199.         end
  200.       end
  201.       if bestjugada == nil
  202.         trymethod2
  203.       else
  204.         @index = bestjugada[0][0]
  205.         @indexboardx = bestjugada[0][1][0]
  206.         @indexboardy = bestjugada[0][1][1]
  207.       end
  208.       # ---------------------------------------------------
  209.       # Animar Deck
  210.       if lastanimate > -1
  211.         card = @enemydeck[lastanimate]
  212.         card[0].x -= 17
  213.         card[0].y -= 6
  214.         card[0].z = lastanimate
  215.       end
  216.       # ---------------------------------------------------
  217.       # ---------------------------------------------------------------------
  218.      
  219.     end
  220.     # ---------------------------------------------------------------------------
  221.     def boardnilsimulation?
  222.       for x in 0...3
  223.         for y in 0...3
  224.           if @data1[x][y] == nil
  225.             return true
  226.           end
  227.         end
  228.       end
  229.       return false
  230.     end
  231.     # ---------------------------------------------------------------------------
  232.     def checkcasillasjugablessimulation
  233.       casillasjugables = []
  234.       for x in 0...3
  235.         for y in 0...3
  236.           if @data1[x][y] == nil
  237.             casillasjugables.push([x,y])
  238.           end
  239.         end
  240.       end
  241.       return casillasjugables
  242.     end
  243.     # ---------------------------------------------------------------------------
  244.     def cardsgainsimulation?(type = 1)
  245.       n = (type == 1 ? @data2.size : @data3.size)
  246.       for x in 0...3
  247.         for y in 0...3
  248.           if @data1[x][y] != nil and @data1[x][y] != -1 and
  249.              @data1[x][y][0] == type
  250.             n += 1
  251.           end
  252.         end
  253.       end
  254.       return n
  255.     end
  256.     # ---------------------------------------------------------------------------
  257.     def checkplaysimulation(type)
  258.       card = @data1[@indexboardx][@indexboardy]
  259.       atacante = card[0]
  260.       power_atk = card[1].dup # Valores de ataque
  261.       plus_atk = card[2] # Plus de ataque de la carta (según elemental)
  262.       for i in 0...4
  263.         power_atk[i] += plus_atk
  264.         power_atk[i] = 1  if power_atk[i] < 1
  265.         power_atk[i] = 10 if power_atk[i] > 10
  266.       end
  267.       @gaincards = []
  268.       @chaincards = []
  269.       @animatecardsflip = []
  270.       cardsbattle = getcardsvssimulation(atacante)
  271.       check_atksimulation(power_atk,atacante,cardsbattle) if cardsbattle.size > 0
  272.       check_battle_resultsimulation(atacante)
  273.       @forzechain = true
  274.       firstchain = true
  275.       # ********************************************************************
  276.       # Inicio Combo System
  277.       # ********************************************************************
  278.       cnt = 0
  279.       while @chaincards.size > 0 and @reglacombo
  280.         return if cnt >= 4
  281.         cards = @chaincards.dup
  282.         @chaincards = []
  283.         @gaincards = []
  284.         combosoundoandtextoneonly = false
  285.         cards.each do |item|
  286.           card = item[0]
  287.           x = item[1]
  288.           y = item[2]
  289.           @indexboardx = x
  290.           @indexboardy = y
  291.           cardsbattle = getcardsvssimulation(atacante)
  292.           power_atk = card[1].dup # Valores de ataque
  293.           plus_atk = card[2] # Plus de ataque de la carta (según elemental)
  294.           for i in 0...4
  295.             power_atk[i] += plus_atk
  296.             power_atk[i] = 1  if power_atk[i] < 1
  297.             power_atk[i] = 10 if power_atk[i] > 10
  298.           end
  299.           checknormalatksimulation(power_atk,cardsbattle)
  300.         end
  301.         cnt += 1
  302.         if @gaincards.size > 0
  303.           check_battle_resultsimulation(atacante)
  304.         else
  305.           break
  306.         end
  307.       end
  308.       @forzechain = false
  309.       # ********************************************************************
  310.       # Fin Combo System
  311.       # ********************************************************************
  312.       checknumbercardsindeck
  313.       checkendgame
  314.       return
  315.     end
  316.     # ---------------------------------------------------------------------------
  317.     def getcardsvssimulation(atacante)
  318.       cardsbattle = []
  319.       if @indexboardx-1 >= 0
  320.         x = @indexboardx-1
  321.         y = @indexboardy
  322.         if @data1[x][y] != nil and @data1[x][y] != -1
  323.           own = @data1[0]
  324.           cardsbattle.push([@data1[x][y],x,y]) if own != atacante
  325.         end
  326.       end
  327.       if @indexboardx+1 <= 2
  328.         x = @indexboardx+1
  329.         y = @indexboardy
  330.         if @data1[x][y] != nil and @data1[x][y] != -1
  331.           own = @data1[0]
  332.           cardsbattle.push([@data1[x][y],x,y]) if own != atacante
  333.         end
  334.       end
  335.       if @indexboardy-1 >= 0
  336.         x = @indexboardx
  337.         y = @indexboardy-1
  338.         if @data1[x][y] != nil and @data1[x][y] != -1
  339.           own = @data1[0]
  340.           cardsbattle.push([@data1[x][y],x,y]) if own != atacante
  341.         end
  342.       end
  343.       if @indexboardy+1 <= 2
  344.         x = @indexboardx
  345.         y = @indexboardy+1
  346.         if @data1[x][y] != nil and @data1[x][y] != -1
  347.           own = @data1[0]
  348.           cardsbattle.push([@data1[x][y],x,y]) if own != atacante
  349.         end
  350.       end
  351.       return cardsbattle
  352.     end
  353.     # ---------------------------------------------------------------------------
  354.     def check_atksimulation(power_atk,atacante,cardsbattle)
  355.       checkreglaparedsimulation(power_atk,atacante)  if @reglapared
  356.       checkreglaigualsimulation(power_atk,atacante)  if @reglaigual
  357.       checkreglasumasimulation(power_atk,atacante)   if @reglasuma
  358.       checknormalatksimulation(power_atk,cardsbattle)
  359.     end
  360.     # ---------------------------------------------------------------------------
  361.     def checkreglaparedsimulation(atk,atacante)
  362.       # La regla pared no toma en cuenta el modificador elemental
  363.       @samewall = false
  364.       @pluswall = false
  365.       return if (@indexboardx == 1 and @indexboardy == 1)
  366.       x = @indexboardx
  367.       y = @indexboardy
  368.       atk = @data1[x][y][1]
  369.       jugadas = {
  370.       # pos => [[lugares con valor 10],[cartas enfrentadas]]
  371.         '00' => [[0,1],[[[x+1,y],[2,1]],[[x,y+1],[3,0]]]],
  372.         '01' => [[1],[[[x+1,y],[2,1]],[[x,y+1],[3,0]],[[x,y-1],[0,3]]]],
  373.         '02' => [[1,3],[[[x+1,y],[2,1]],[[x,y-1],[0,3]]]],
  374.         '10' => [[0],[[[x+1,y],[2,1]],[[x-1,y],[1,2]],[[x,y+1],[3,0]]]],
  375.         '12' => [[3],[[[x+1,y],[2,1]],[[x-1,y],[1,2]],[[x,y-1],[0,3]]]],
  376.         '20' => [[0,2],[[[x-1,y],[1,2]],[[x,y+1],[3,0]]]],
  377.         '21' => [[2],[[[x-1,y],[1,2]],[[x,y-1],[0,3]],[[x,y+1],[3,0]]]],
  378.         '22' => [[2,3],[[[x-1,y],[1,2]],[[x,y-1],[0,3]]]]
  379.       }
  380.       id = "#{x}#{y}"
  381.       jugada = jugadas[id]
  382.       jugada[1].each do |card|
  383.         x = card[0][0]
  384.         y = card[0][1]
  385.         atkv = card[1][0]
  386.         defv = card[1][1]
  387.         next if @data1[x][y] == nil or @data1[x][y] == -1
  388.         def_real = @data1[x][y][1][3][defv] #+ @boarddeck[x][y][3]
  389.         def_real = 10 if def_real > 10
  390.         def_real = 1  if def_real < 1
  391.         next if @data1[x][y] == nil or @data1[x][y] == -1
  392.         next if @data1[x][y][0] == atacante
  393.         jugada[0].each do |value|
  394.           if atk[value] == 10 and def_real == atk[atkv]
  395.             if !@gaincards.include?(@data1[x][y])
  396.               @gaincards.push(@data1[x][y])
  397.             end
  398.             if @usecombowithwall
  399.               if !@chaincards.include?([@data1[x][y],x,y])
  400.                 @chaincards.push([@data1[x][y],x,y])
  401.               end
  402.             end
  403.           elsif (atk[value] + 10) == (def_real + atk[atkv]) and @usepluswall
  404.             if !@gaincards.include?(@data1[x][y])
  405.               @gaincards.push(@data1[x][y])
  406.             end
  407.             if @usecombowithwall
  408.               if !@chaincards.include?(@data1[x][y])
  409.                 @chaincards.push([@data1[x][y],x,y])
  410.               end
  411.             end
  412.           end
  413.         end
  414.       end
  415.     end
  416.     # ---------------------------------------------------------------------------
  417.     def checkreglaigualsimulation(atk,atacante)
  418.       # La regla igual no toma en cuenta el modificador elemental
  419.       x = @indexboardx
  420.       y = @indexboardy
  421.       atk = @data1[x][y][1]
  422.       jugadas = [
  423.         #  [carta1,carta2,check1,check2]
  424.         [[x,y-1],[x+1,y],[0,3],[2,1]],
  425.         [[x,y-1],[x,y+1],[0,3],[3,0]],
  426.         [[x,y-1],[x-1,y],[0,3],[1,2]],
  427.         [[x+1,y],[x,y+1],[2,1],[3,0]],
  428.         [[x+1,y],[x-1,y],[2,1],[1,2]],
  429.         [[x-1,y],[x,y+1],[1,2],[3,0]]
  430.       ]
  431.       jugadas.each do |jugada|
  432.         x1 = jugada[0][0]
  433.         y1 = jugada[0][1]
  434.         x2 = jugada[1][0]
  435.         y2 = jugada[1][1]
  436.         check1a = jugada[2][0]
  437.         check1b = jugada[2][1]
  438.         check2a = jugada[3][0]
  439.         check2b = jugada[3][1]
  440.         next if x1 < 0 or x1 > 2 or x2 < 0 or x2 > 2 or
  441.                 y1 < 0 or y1 > 2 or y2 < 0 or y2 > 2
  442.         if @data1[x1][y1] != nil and @data1[x1][y1] != -1 and
  443.            @data1[x2][y2] != nil and @data1[x2][y2] != -1
  444.            if (@data1[x1][y1][0] != atacante and
  445.               @data1[x2][y2][0] != atacante and !@checkallcards) or
  446.               @checkallcards
  447.               def1 = @data1[x1][y1][1][check1b]
  448.               def2 = @data1[x2][y2][1][check2b]
  449.               def1 = 10 if def1 > 10
  450.               def1 = 1 if def1 < 1
  451.               def2 = 10 if def2 > 10
  452.               def2 = 1 if def2 < 1
  453.               if def1 == atk[check1a] and
  454.                  def2 == atk[check2a]
  455.                  if @data1[x1][y1][0] != atacante
  456.                    if !@gaincards.include?(@data1[x1][y1])
  457.                     @gaincards.push(@data1[x1][y1])
  458.                    end
  459.                    if !@chaincards.include?([@data1[x1][y1],x1,y1])
  460.                     @chaincards.push([@data1[x1][y1],x1,y1])
  461.                    end
  462.                  end
  463.                  if @data1[x2][y2][0] != atacante
  464.                    if !@gaincards.include?(@data1[x2][y2])
  465.                     @gaincards.push(@data1[x2][y2])
  466.                    end
  467.                    if !@chaincards.include?([@data1[x2][y2],x2,y2])
  468.                     @chaincards.push([@data1[x2][y2],x2,y2])
  469.                    end
  470.                  end
  471.               end
  472.            end
  473.         end  
  474.       end
  475.     end
  476.     # ---------------------------------------------------------------------------
  477.     def checkreglasumasimulation(atk,atacante)
  478.       # La regla suma no toma en cuenta el modificador elemental
  479.       x = @indexboardx
  480.       y = @indexboardy
  481.       atk = @data1[x][y][1]
  482.       jugadas = [
  483.         #  [carta1,carta2,checkatk1,checkatk2]
  484.         [[x,y-1],[x+1,y],[0,3],[2,1]],
  485.         [[x,y-1],[x,y+1],[0,3],[3,0]],
  486.         [[x,y-1],[x-1,y],[0,3],[1,2]],
  487.         [[x+1,y],[x,y+1],[2,1],[3,0]],
  488.         [[x+1,y],[x-1,y],[2,1],[1,2]],
  489.         [[x-1,y],[x,y+1],[1,2],[3,0]]
  490.       ]
  491.       jugadas.each do |jugada|
  492.         x1 = jugada[0][0]
  493.         y1 = jugada[0][1]
  494.         x2 = jugada[1][0]
  495.         y2 = jugada[1][1]
  496.         check1a = jugada[2][0]
  497.         check1b = jugada[2][1]
  498.         check2a = jugada[3][0]
  499.         check2b = jugada[3][1]
  500.         next if x1 < 0 or x1 > 2 or x2 < 0 or x2 > 2 or
  501.                 y1 < 0 or y1 > 2 or y2 < 0 or y2 > 2
  502.         if @data1[x1][y1] != nil and @data1[x1][y1] != -1 and
  503.            @data1[x2][y2] != nil and @data1[x2][y2] != -1
  504.            if (@data1[x1][y1][0] != atacante and
  505.               @data1[x2][y2][0] != atacante and !@checkallcards) or
  506.               @checkallcards
  507.               def1 = @data1[x1][y1][1][check1b]
  508.               def2 = @data1[x2][y2][1][check2b]
  509.               def1 = 10 if def1 > 10
  510.               def1 = 1 if def1 < 1
  511.               def2 = 10 if def2 > 10
  512.               def2 = 1 if def2 < 1
  513.               if def1 + atk[check1a] == def2 + atk[check2a]
  514.                  if @data1[x1][y1][0] != atacante
  515.                    if !@gaincards.include?(@data1[x1][y1])
  516.                     @gaincards.push(@data1[x1][y1])
  517.                    end
  518.                    if !@chaincards.include?([@data1[x1][y1],x1,y1])
  519.                     @chaincards.push([@data1[x1][y1],x1,y1])
  520.                    end
  521.                  end
  522.                  if @data1[x2][y2][0] != atacante
  523.                    if !@gaincards.include?(@data1[x2][y2])
  524.                     @gaincards.push(@data1[x2][y2])
  525.                    end
  526.                    if !@chaincards.include?([@data1[x2][y2],x2,y2])
  527.                     @chaincards.push([@data1[x2][y2],x2,y2])
  528.                    end
  529.                  end
  530.               end
  531.            end
  532.         end  
  533.       end
  534.     end
  535.     # ---------------------------------------------------------------------------
  536.     def checknormalatksimulation(atk,cards)
  537.       # Ataque normal: toma en cuenta valores ataque y el modificador elemental
  538.       cards.each do |card|
  539.         power_atk = card[0][1].dup
  540.         plus_atk = card[0][2] # Plus de ataque de la carta (según elemental)
  541.         for i in 0...4
  542.           power_atk[i] += plus_atk
  543.           power_atk[i] = 1  if power_atk[i] < 1
  544.           power_atk[i] = 10 if power_atk[i] > 10
  545.         end
  546.         if (card[1] == @indexboardx-1 and card[2] == @indexboardy and
  547.           atk[1] > power_atk[2]) or
  548.           (card[1] == @indexboardx+1 and card[2] == @indexboardy and
  549.           atk[2] > power_atk[1]) or
  550.           (card[1] == @indexboardx and card[2] == @indexboardy-1 and
  551.           atk[0] > power_atk[3]) or
  552.           (card[1] == @indexboardx and card[2] == @indexboardy+1 and
  553.           atk[3] > power_atk[0])
  554.           @gaincards.push(card[0]) if !@gaincards.include?(card[0])
  555.           x = (card[1] != @indexboardx ? card[1] : @indexboardx)
  556.           y = (card[2] != @indexboardy ? card[2] : @indexboardy)
  557.           if @forzechain
  558.             if !@chaincards.include?([card[0],x,y])
  559.               @chaincards.push([card[0],x,y])
  560.             end
  561.           end
  562.         end
  563.       end
  564.     end
  565.     # ---------------------------------------------------------------------------
  566.     def check_battle_resultsimulation(atacante)
  567.       if @gaincards.size > 0
  568.         verifychecksimulation(atacante,@gaincards)
  569.       end
  570.     end
  571.     # ---------------------------------------------------------------------------
  572.     def verifychecksimulation(atacante,cards)
  573.       imas = []
  574.       cards.each do |item|
  575.         item[0] = atacante
  576.       end
  577.     end
  578.     # ---------------------------------------------------------------------------
  579.     def chargedatasimulation
  580.       file = File.open('tempcardsdata', "rb")
  581.       @data1 = Marshal.load(file)
  582.       @data2 = Marshal.load(file)
  583.       @data3 = Marshal.load(file)
  584.       file.close
  585.     end
  586.       def ahora
  587.       boarddata = [Array.new(3),Array.new(3),Array.new(3)]
  588.       playerdata = []
  589.       enemydata = []
  590.       for x in 0...3
  591.         for y in 0...3
  592.           data = @boarddeck[x][y]
  593.           if data != nil and data != -1
  594.             atk = data[2][3].dup
  595.             boarddata[x][y] = [data[2][5],atk,data[3]]
  596.           else
  597.             boarddata[x][y] = data
  598.           end
  599.         end
  600.       end
  601.       @playerdeck.each do |item|
  602.         atk = item[2][3].dup
  603.         playerdata.push([0,atk,item[3]])
  604.       end
  605.       @enemydeck.each do |item|
  606.         atk = item[2][3].dup
  607.         enemydata.push([1,atk,item[3]])
  608.       end
  609.       @data1 = boarddata
  610.       @data2 = playerdata
  611.       @data3 = enemydata
  612.     end
  613.     # ---------------------------------------------------------------------------
  614.     def trymethod2
  615.       @index = rand(@enemydeck.size)
  616.       casillasjugables = checkcasillasjugables
  617.       casilla = casillasjugables[rand(casillasjugables.size)]
  618.       @indexboardx = casilla[0]
  619.       @indexboardy = casilla[1]
  620.     end
  621.     # ---------------------------------------------------------------------------
  622.   end
  623. # ******************************************************************************
  624. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement