othello

this is my print_r

local M = {} function M.print\_r ( t ) --end --at the very bottom of print\_r.lua paste this local function print\_r ( t ) local print\_r\_cache={} local function sub\_print\_r(t,indent) if (print\_r\_cache[tostring(t)]) then print(indent.."\*"..tostring(t)) else print\_r\_cache[tostring(t)]=true if (type(t)=="table") then local tLen = #t for i = 1, tLen do local val = t[i] if (type(val)=="table") then print(indent.."#["..i.."] =\> "..tostring(t).." {") sub\_print\_r(val,indent..string.rep(" ",string.len(i)+8)) print(indent..string.rep(" ",string.len(i)+6).."}") elseif (type(val)=="string") then print(indent.."#["..i..'] =\> "'..val..'"') else print(indent.."#["..i.."] =\> "..tostring(val)) end end for pos,val in pairs(t) do if type(pos) ~= "number" or math.floor(pos) ~= pos or (pos \< 1 or pos \> tLen) then if (type(val)=="table") then print(indent.."["..pos.."] =\> "..tostring(t).." {") sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8)) print(indent..string.rep(" ",string.len(pos)+6).."}") elseif (type(val)=="string") then print(indent.."["..pos..'] =\> "'..val..'"') else print(indent.."["..pos.."] =\> "..tostring(val)) end end end else print(indent..tostring(t)) end end end if (type(t)=="table") then print(tostring(t).." {") sub\_print\_r(t," ") print("}") else sub\_print\_r(t," ") end print() end end return M

is that correct?

and kindly try my code, i don’t really know where is my mistake

:frowning:

-- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here local DisplayGroup = display.newGroup() --declare display group to hold display objects local T = {} --replace Chips1 table below with a Table labeled "T" local text = {} local print\_r=require ("print\_r") cy=display.contentCenterY cx=display.contentCenterX function startGame( event) --remove all display objects and respawn the game board, this is an easy way to restart the game display.remove(DisplayGroup) DisplayGroup = nil DisplayGroup = display.newGroup() local background2= display.newRect(cx,cy,360, 650) background2.alpha=0 background2:setFillColor( 0 ) DisplayGroup:insert(background2) local cbs2= display.newRect(cx, cy-220,320, 100) cbs2:setFillColor( 0.5 ) local board1= display.newRect(cx,cy,320,320) board1.alpha=0 board1:setFillColor( 0 ) DisplayGroup:insert(cbs2) -- body transition.to(background2,{time=1000, alpha=1, x=centerX,y=200}) -- transition.to(board1,{time=1000, alpha=1, x=centerX,y=centerY}) grid() end local function validPlay(col, row, state) print("validPlay("..col..", "..row..", "..state..") is called") local Col local Row local State = state --color of current play local CaptureTable = {} --create a table to hold Chips that are to be capture local CellTable = {} -- table to hold coordinates of all Cellls in the Up direction local \_index --this will be an Integer use for a temporary index local tempCol local tempRow local validVector = "false" --------- each vector will have similar to this print("#1 --Start Up Vector iteration") --check UP vetor, so Row is row -1 Col = col Row = row -1 print("col == ",col) print("row == ",row) print("Col == ",Col) print("Row == ",Row) print("T[Col][Row].state == ",T[Col][Row].state) if T[Col][Row] ~= nil then --check to see if Cell above exists, if not, do nothing if T[Col][Row].state == "blank" then --do nothing print("Up vector-- Cell has no Chip") elseif T[Col][Row].state ~= State then --check to see if Cell above is opposite color --since cell above is valid, create table of all cells above to row 1 CellTable = nil --clear the CellTable CellTable = {} tempRow = row --store the original row value in play for i = Row, 1 , -1 do -- add all cells above cell in play to CellTable tempRow = tempRow -1 \_index = #CellTable + 1 CellTable[\_index] = {} CellTable[\_index].col = Col CellTable[\_index].row = tempRow end print("\*\*\*Up vector / CellTable prints below") print\_r.print\_r(CellTable) for i = 1, #CellTable do --starting near cell in play, put all Cells above of opposite color into a CaptureTable if T[CellTable[i].col][CellTable[i].row].state ~= State and T[CellTable[i].col][CellTable[i].row].state ~= "blank" then \_index = #CaptureTable + 1 CaptureTable[\_index] = {} CaptureTable[\_index].col = Col CaptureTable[\_index].row = Row elseif T[CellTable[i].col][CellTable[i].row].state == State then --when a cell with the same color is found, stop adding cells to CaptureTable print("break--cell matches State color") break end end print("\*\*\*Up vector / CellTable prints below") print\_r.print\_r(CaptureTable) end end ----------end Up vector code --next vector code goes here and so on ------- print("#2 --Start Up\_Right Vector iteration") --check UP\_Right vetor, so Row is row -1 Col = col +1 Row = row -1 print("col == ",col) print("row == ",row) print("Col == ",Col) print("Row == ",Row) print("T[Col][Row].state == ",T[Col][Row].state) if T[Col][Row] ~= nil then --check to see if Cell above exists, if not, do nothing if T[Col][Row].state == "blank" then --do nothing print("Up\_Right vector-- Cell has no Chip") elseif T[Col][Row].state ~= State then --check to see if Cell above is opposite color --since cell above is valid, create table of all cells above to row 1 CellTable = nil --clear the CellTable CellTable = {} --cell in play example coordinate (1,4) col = 1, row = 4 tempCol = col tempRow = row for i = Row, 1 , -1 do tempCol = tempCol +1 tempRow = tempRow -1 \_index = #CellTable + 1 CellTable[\_index] = {} CellTable[\_index].col = tempCol CellTable[\_index].row = tempRow end print("\*\*\*Up\_Right vector / CellTable prints below") print\_r.print\_r(CellTable) for i = 1, #CellTable do --starting near cell in play, put all Cells above of opposite color into a CaptureTable if T[CellTable[i].col][CellTable[i].row].state ~= State and T[CellTable[i].col][CellTable[i].row].state ~= "blank" then \_index = #CaptureTable + 1 CaptureTable[\_index] = {} CaptureTable[\_index].col = Col CaptureTable[\_index].row = Row elseif T[CellTable[i].col][CellTable[i].row].state == State then --when a cell with the same color is found, stop adding cells to CaptureTable print("break--cell matches State color") break end end print("\*\*\*Up\_Right vector / CellTable prints below") print\_r.print\_r(CaptureTable) end end ----------end Up\_Right vector code --next vector code goes here and so on ------- return CaptureTable -- return the CaptureTable back to gridTapped(event) end function grid() local playCount = 0 local clicked=0 local clicked1=0 local chip function chipTapped(event) local button = event.target local button1=event.target local col = button.col local row = button.row local State = "Void" --we will change the state to a string, "ehite" or "black" playCount = playCount + 1 clicked=clicked+1 print("\*clicked == ",clicked) if clicked == 1 then State = "black" elseif clicked == 2 then State = "white" else clicked=0 end if (button.state=="blank") then ------------ get table of Chips to flip local FlipTable = validPlay(col, row, State) print("#FlipTable == ",#FlipTable) if #FlipTable \>= 1 then print("\*#FlipTable == ",#FlipTable) playCount = playCount + 1 local FlipColor --New variable to hold the FlipColor to be used in transition.to below if clicked == 1 then --State = "black" FlipColor = 0 elseif clicked == 2 then --State = "white" FlipColor = 1 end for i = 1, #FlipTable do T[FlipTable[i].col][FlipTable[i].row].state = State -- T[FlipTable[i].col][FlipTable[i].row]:setFillColor(clicked) transition.to( T[FlipTable[i].col][FlipTable[i].row].Chip.fill, { r=FlipColor, g=FlipColor, b=FlipColor, a=1, time=500, transition=easing.inCubic }) end else print("\*\*\*return / NOT a valid move") return end ------------ if (clicked==1) then button.state=1 endtxt = display.newText( clicked, 0, 0, native.systemFont, 24 ) endtxt.x=display.contentCenterX endtxt.y=display.contentCenterY transition.to( endtxt, {time=1500,alpha=0}) T[col][row].state = State T[col][row].originColor = "black" --need to set color T[col][row].originPlayCount = playCount T[col][row].Chip:setFillColor(0) T[col][row].Chip.isVisible = true clicked=1 chip="black" print("\*\*clicked == ",clicked) --return blackpiece end if (clicked==2) then button.state=0 --set state below, this works fine, just setting variable in 1 area endtxt1 = display.newText( clicked, 0, 0, native.systemFont, 24 ) endtxt1.x=display.contentCenterX endtxt1.y=display.contentCenterY transition.to( endtxt1, {time=1500,alpha=0}) T[col][row].state = State T[col][row].originColor = "white" T[col][row].originPlayCount = playCount T[col][row].Chip:setFillColor(1) T[col][row].Chip.isVisible = true clicked=clicked-2 print("\*\*clicked == ",clicked) chip="white" --return whitepiece end else if (chip=="white") then clicked=0 end if (chip=="black") then clicked=1 end end print("{x=" ..event.target.gridPos.x .. ", y=" .. event.target.gridPos.y .. "}") text.alpha = 1 -- text.text = "{x=" ..event.target.gridPos.x .. ", y=" .. event.target.gridPos.y .. "}" text.text = "State= "..State.." / col= "..col.." / row= "..row.."" transition.to(text,{time=1500, alpha=0}) end --======================================== -- grid code --======================================== local chipWidth = 38 local chipHeight = 38 local colSpace =0 local rowSpace =0 local numCols = 8 local numRows = 8 local centerY=display.contentCenterY local centerX= display.contentCenterX local xPos = centerX- (numCols \* chipWidth + numCols \* colSpace) / 2 local yPos = centerY - (numRows \* chipHeight + numRows \* rowSpace) / 2 --clear table and respawn, display objects have already been removed in "startGame" when the DisplayGroup was cleared/removed T = nil T = {} for col=1,numCols do T[col] = {} --creates an indexed table for each col for row=1, numRows do T[col][row] = {} --creates an indexed table for each row in each col, look familiar? --T[1][1] will be the upper left square, T[8][8] will be the lower right square T[col][row]= display.newRect(0,0,chipWidth,chipHeight) T[col][row].x = xPos + col \* (chipWidth + colSpace) - chipWidth/2 - colSpace T[col][row].y = yPos + row\* (chipHeight + rowSpace) - chipHeight/2 - rowSpace T[col][row].strokeWidth = 1 --add grid lines T[col][row]:setStrokeColor(1) --sets grid color black T[col][row]:setFillColor(0.3, 0.6, 0.8) T[col][row].alpha=0.5 T[col][row].gridPos = {x=col, y=row} -- I'm going to seperate the gridPos references, it may be easier, not sure yet' T[col][row].col = col T[col][row].row = row T[col][row].state="blank" T[col][row].originColor = "Void" --will store the player color when first played T[col][row].originPlayCount = 0 --will store the index when first played T[col][row]:addEventListener("tap",chipTapped) DisplayGroup:insert(T[col][row]) --add object to the display group T[col][row].Chip = display.newCircle(cx,cy,15) T[col][row].Chip:setFillColor(1) T[col][row].Chip.x = T[col][row].x T[col][row].Chip.y = T[col][row].y --T[col][row].Chip.width=event.target.width --T[col][row].Chip.height=event.target.height T[col][row].Chip.isVisible = false -- hide the Chip until played DisplayGroup:insert(T[col][row].Chip) end end text = display.newText( "Void", 0, 0, "Helvetica", 24 ) text.x = display.contentCenterX-60 --text.y = display.contentCenterY-60 text.y = 60 text.alpha=1 text:setTextColor(255, 254, 185) DisplayGroup:insert(text) transition.to(text,{time=1500, alpha=0}) local function start() T[4][5].originColor="black" T[4][5].originPlayCount = playCount T[4][5].Chip:setFillColor(0) T[4][5].Chip.isVisible = true T[4][5].state="black" T[4][5].originColor = "black" T[4][5].originPlayCount = 0 T[5][4].originColor="black" T[5][4].originPlayCount = playCount T[5][4].Chip:setFillColor(0) T[5][4].Chip.isVisible = true T[5][4].state="black" T[5][4].originColor = "black" T[5][4].originPlayCount = 0 T[5][5].originColor="white" T[5][5].originPlayCount = playCount T[5][5].Chip:setFillColor(1) T[5][5].Chip.isVisible = true T[5][5].state="white" T[5][5].originColor = "white" T[5][5].originPlayCount = 0 T[4][4].originColor="white" T[4][4].originPlayCount = playCount T[4][4].Chip:setFillColor(1) T[4][4].Chip.isVisible = true T[4][4].state="white" T[4][4].originColor = "white" T[4][4].originPlayCount = 0 end function vector() local Up= T[col][row-1] Up\_Right= T[col+1][row-1] Right=T[col+1][row] Down\_Right=T[col+1][row+1] Down=T[col][row+1] Down\_Left=T[col-1][row+1] Left=T[col-1][row] Up\_Left=T[col-1][row-1] Center=T[col][row] end function get\_neighbor(col, row, vector) local obj = nil local vx, vy = self:get\_vector(vector) if vx ~= nil then col = col + vx row = row + vy if self:is\_valid(col, row) then obj = self:get\_cell(col, row) end end return obj end start() end startGame()

ok, here is the fix for your print_r.lua

This is how you setup a module so it’s functions can be called from another file/module that requires it.

any functions that are to be called from another file/module need to be put in a table that is returned when the other file/module calls it.

you cannot call a “local” function in a module from a separate module, it has to be a table function.

so when we declare “function M.print_r(t)”  , we are adding the print_(t) function to the M table of the module.

I’m adding another function to print_r.lua. 

M.prirnt_helloWorld()

it just prints “Hello World” when called from main.lua.  print_r.print_helloWorld()

-- print\_r.lua local M = {} -- function M.print\_helloWorld() -- print("Hello World") end function M.print\_r ( t ) --local function print\_r ( t ) --this is replaced with a table function declaration M.print\_r(t) local print\_r\_cache={} local function sub\_print\_r(t,indent) if (print\_r\_cache[tostring(t)]) then print(indent.."\*"..tostring(t)) else print\_r\_cache[tostring(t)]=true if (type(t)=="table") then local tLen = #t for i = 1, tLen do local val = t[i] if (type(val)=="table") then print(indent.."#["..i.."] =\> "..tostring(t).." {") sub\_print\_r(val,indent..string.rep(" ",string.len(i)+8)) print(indent..string.rep(" ",string.len(i)+6).."}") elseif (type(val)=="string") then print(indent.."#["..i..'] =\> "'..val..'"') else print(indent.."#["..i.."] =\> "..tostring(val)) end end for pos,val in pairs(t) do if type(pos) ~= "number" or math.floor(pos) ~= pos or (pos \< 1 or pos \> tLen) then if (type(val)=="table") then print(indent.."["..pos.."] =\> "..tostring(t).." {") sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8)) print(indent..string.rep(" ",string.len(pos)+6).."}") elseif (type(val)=="string") then print(indent.."["..pos..'] =\> "'..val..'"') else print(indent.."["..pos.."] =\> "..tostring(val)) end end end else print(indent..tostring(t)) end end end if (type(t)=="table") then print(tostring(t).." {") sub\_print\_r(t," ") print("}") else sub\_print\_r(t," ") end print() --end end return M

You main.lua file posted above doesn’t include the cell validator code (which will be needed in ALL vector code blocks.

You’d better re-read my post 321 to understand why this is needed and where it goes.

 --new cell validator --This is needed in ALL vector blocks if tempCol \> 8 or tempCol \< 1 or tempRow \> 8 or tempRow \< 1 then --verify values are not out of range print("\*\*UpRight -- Cell out of Ranged") print("\*\*UpRight break") break --calling break will stop the loop when a condition is met, so no more cells will be added to the CellTable end

let’s focus on the UpRight vector code block and get it working, then you can use it as a template for the other 7 vectors. just post your code from the UpRight vector code block until we get it working.

FWIW, there are other modifications to be made to the UpRight code block loop.  As we add cells along the vector to the CellTable, we need to verify there are no “blank” cells and verify that the vector is bound by a chip with the same State.  The loop also needs to stop adding chips beyond the bounding chip of a valid vector.

Nail

Thank you Sir

I had finish the up_right, I will start doing the 6 on school later, thank you again :slight_smile:

Don’t think that I surrender this project because I will never will :slight_smile:

I think yo had better get the UpRight vector working better first.

With just the Up and UpRight vector code, select 5,6 first black play, then 4,6 as first white play.

Are there unexpected results?

Nail

There is no unexpected result, except the flipping of more than 1 and the double tap error

The flipping of more that one chip is the “unexpected result” when only 1 chip should be flipped, chip 4,5.

Only chip 4,5 should get flipped when 4,6 is selected, but chip 5,5 is getting flipped also.  This should NOT happen.

I’m assuming you have the print_r.lua working now.  You will need to look at the CellTable and the CaptureTable results printed in the console.

There is a typo near the bottom of your UpRight vector code block.

print("***Up_Right vector / CellTable prints below")
            print_r.print_r(CaptureTable)

Change to this so the print out of the CaptureTable in the console is not confusing.

print("***Up_Right vector / CaptureTable prints below")
            print_r.print_r(CaptureTable)

When 4,6 is selected, the UpRight vector code is adding 4 cells to the CellTable.  It’s adding ALL the cells along the UpRight vector to the CellTable,  This is problem with the code we must fix.

\*\*\*Up\_Right vector / CellTable prints below table: 0x7fbc80553a60 { #[1] =\> table: 0x7fbc80553a60 { [row] =\> 5 [col] =\> 5 } #[2] =\> table: 0x7fbc80553a60 { [row] =\> 4 [col] =\> 6 } #[3] =\> table: 0x7fbc80553a60 { [row] =\> 3 [col] =\> 7 } #[4] =\> table: 0x7fbc80553a60 { [row] =\> 2 [col] =\> 8 } }

The good news is the code block is adding cells along the vector, but we have to limit the cells it’s capturing with Conditional statements in our loop.

the code needs to ONLY add chips along the vector that are colored and do not have a state == “blank”.  If we find a cell that is “blank” or empty, we need to stop the vector code from adding these cells to the CellTable.

The code needs to STOP adding cells along the vector when a “blank” cell is found and not add that cell to the CellTable.

The loop will need to “break” when a “blank” cell is found with a conditional statement and stop adding invalid cells to the CellTable.

So in the UpRight vector we are using, how can we determine the .state of cell 5,5 and verify cell 5,5 is colored or “blank”, how can we determine the .state of cell 6,4 and verify cell 6,4 is colored or “blank”?

Since we spawned the cells of the game board into a table, and we know the cells coordinates are the same as the cells table value indexes, we can find the .state of any cell at anytime.

We need a conditional statement inside the loop to be met or not met before we add the cell along a vector to the CellTable.

something like this…

--this is for concept only if Cell.state == "blank" then --an empty cell has been found --when this condition is met, the loop will stop adding cells to the CellTable when we call break break else add the Cell on the vector to the CellTable end

Nail

should I write this way Sir?

 for i = Row, 1 , -1 do tempCol = tempCol +1 tempRow = tempRow -1 --new cell validator --This is needed in ALL vector blocks if tempCol \> 8 or tempCol \< 1 or tempRow \> 8 or tempRow \< 1 or T[tempCol][tempRow].state=="blank".state=="blank" then --verify values are not out of range print("\*\*UpRight -- Cell out of Ranged") print("\*\*UpRight break") break --calling break will stop the loop when a condition is met, so no more cells will be added to the CellTable end \_index = #CellTable + 1 CellTable[\_index] = {} CellTable[\_index].col = tempCol CellTable[\_index].row = tempRow end

The location of the conditional statement will work, but there is a syntax error, it won’t run in the simulator because there is an error.

FWiW, you could put the conditional statement on it’s own, as long as it is located below the first cell validator chunk.  Your location may be faster.

--new cell validator&nbsp; --This is needed in ALL vector blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if tempCol \> 8 or tempCol \< 1 or tempRow \> 8 or tempRow \< 1 then&nbsp; --verify values are not out of range &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("\*\*"..VT[k].vector.." -- Cell out of Ranged") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("\*\*"..VT[k].vector.." break") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break&nbsp;&nbsp; --calling break will stop the loop when a condition is met, so no more cells will be added to the CellTable &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if T[tempCol][tempRow].state == "blank" then --stop building CellTable if a "blank" cell is found break --stops the loop and goes to next vector block end 

Did you try to run your code in the simulator?  You should try to run your code and debug the problems on your own before you post.

--this is your line, -- or T[tempCol][tempRow].state=="blank".state=="blank" then --FYI, you can't compare 3 items in a conditional, only 2 -- =="blank".state== / this variable does not exist in the project, so you can't compare it to anything, it will kick en error --the conditional should read: or T[tempCol][tempRow].state=="blank" then --"blank", "black", "white" are our 3 possible values for the .state property of each cell

btw, all the vector code blocks will need this cell validator chunk, add it to your Up vector code block also. We never want to add “blank” cells to the CellTable.

Fix your code and run it.  select the same 2 cells we have been using 5,6 then 4,6.  are there unexpected results?

Nail

UPDATE: MODULE Released --> https://forums.coronalabs.com/topic/71820-reversi-aka-othello-module-complete/

I’ve been watching this thread with interest for a while.  It inspired me to spend some time today making a Reversi module and a game supporting:

  • Player Versus AI 
  • Player Versus Player
  • AI Versus AI

The AI versus AI is running in this video and playing at the highest speed of one move per frame with 2 seconds between games.

I’m going to release the module and a full set of game examples tomorrow (Wed Feb 21 2018) on Sellfy.  I’ll also post it to the Marketplace here.

https://forums.coronalabs.com/topic/71820-reversi-aka-othello-module-complete/

https://www.youtube.com/watch?v=I10Sjf2Wzzk&feature=youtu.be

https://www.youtube.com/watch?v=3o-IS3tH4HA&feature=youtu.be

 for i = Row, 1 , -1 do tempCol = tempCol +1 tempRow = tempRow -1 --new cell validator --This is needed in ALL vector blocks if tempCol \> 8 or tempCol \< 1 or tempRow \> 8 or tempRow \< 1 then --verify values are not out of range print("\*\*UpRight -- Cell out of Ranged") print("\*\*UpRight break") print("\*\*"..VT[k].vector.." -- Cell out of Ranged") print("\*\*"..VT[k].vector.." break") break --calling break will stop the loop when a condition is met, so no more cells will be added to the CellTable end if T[tempCol][tempRow].state == "blank" then --stop building CellTable if a "blank" cell is found break --stops the loop and goes to next vector block end \_index = #CellTable + 1 CellTable[\_index] = {} CellTable[\_index].col = tempCol CellTable[\_index].row = tempRow end

#2 --Start Up_Right Vector iteration

23:10:37.251  col == 4

23:10:37.251  row == 6

23:10:37.251  Col == 5

23:10:37.251  Row == 5

23:10:37.251  T[Col][Row].state == black

23:10:37.251  ***Up_Right vector / CellTable prints below

23:10:37.251  table: 09C69390 {

23:10:37.251    #[1] => table: 09C69390 {

23:10:37.251             [row] => 5

23:10:37.251             [col] => 5

23:10:37.251           }

23:10:37.251  }

23:10:37.251  ***Up_Right vector / Capture Table prints below

23:10:37.251  table: 09C68EE0 {

23:10:37.251    #[1] => table: 09C68EE0 {

23:10:37.251             [row] => 5

23:10:37.251             [col] => 4

23:10:37.251           }

23:10:37.251    #[2] => table: 09C68EE0 {

23:10:37.251             [row] => 5

23:10:37.251             [col] => 5

23:10:37.251           }

23:10:37.251  }

23:10:37.251  #FlipTable == 2

23:10:37.251  *#FlipTable == 2

23:10:37.262  **clicked == 0

23:10:37.262  {x=4, y=6}

that line don’t appear on the console Sir

First, in the cell validator chunk I posted above, there are 2 print statements that need to be commented out or remove if you were to use the chunk.  They would kick an error.  I can see you did not use my code chunk above, which is good.

 --new cell validator --This is needed in ALL vector blocks if tempCol \> 8 or tempCol \< 1 or tempRow \> 8 or tempRow \< 1 then --verify values are not out of range print("\*\*UpRight -- Cell out of Ranged") print("\*\*UpRight break") -- these 2 print statements should be removed or commented out, we do not have a VT table -- print("\*\*"..VT[k].vector.." -- Cell out of Ranged") -- print("\*\*"..VT[k].vector.." break") break --calling break will stop the loop when a condition is met, so no more cells will be added to the CellTable end

At the bottom of you post above, you state " That line don’t appear in the console Sir".

I have no idea what you are referring to, could you be more specific.

There is the problem in the code though, your console print out shows the chip 5,5 is being added to the CellTable which is then added to the CaptureTable, so it will be flipped.  This flip should NOT happen because cell 6,4 is blank.  A chip should only be flipped if it is bound on the far side by a chip on the vector with the same color as the color in play.  This is how the game should work, correct?

So the code must verify, with a conditional statement, that the last cell/chjp on the vector is the players color/State before the cells are added to the CaptureTable.

There are a few different ways to accomplish this. Here’s one.

Look at your console print out below, I commented the cell 5,5 that should NOT be added to the CaptureTable to be flipped.

\*\*\*Up\_Right vector / CellTable prints below 23:10:37.251 table: 09C69390 { 23:10:37.251 #[1] =\> table: 09C69390 { 23:10:37.251 [row] =\> 5 23:10:37.251 [col] =\> 5 23:10:37.251 } 23:10:37.251 } 23:10:37.251 \*\*\*Up\_Right vector / Capture Table prints below 23:10:37.251 table: 09C68EE0 { 23:10:37.251 #[1] =\> table: 09C68EE0 { 23:10:37.251 [row] =\> 5 23:10:37.251 [col] =\> 4 23:10:37.251 } 23:10:37.251 #[2] =\> table: 09C68EE0 { --This cell/chip should NOT be flipped, so it should NOT be added to the CaptureTable 23:10:37.251 [row] =\> 5 23:10:37.251 [col] =\> 5 23:10:37.251 } 23:10:37.251 }

the code chunk that adds the cells in the CellTable to the CaptureTable must have a conditional statement preceding it that verifies there is a bounding chip with the players color/state at the end of the vector, which is the last indexed member of the vectors CellTable.  If this condition is NOT met, then no cells along the vector are to be added to the CaptureTable.

So how do we find the last indexed member of the CellTable, which would be the bounding cell and verify it is the player’s color/State? 

#CellTable will return size of the vector’s CellTable, which is also the index of the last table member.  This cell, the bounding cell, must be the players color/State as a condition to be met for the code adding cells to the CaptureTable to continue.  We cannot add cells to the CaptureTable that are not supposed to be flipped.

Let’s add a new variable, BoundingCell, that is a copy of the bounding cell or last indexed member of the CellTable so we can check the game board and verify it’s color/State is the same as the Player’s color/State

local BoundingCell = CellTable[#CellTable] -- this is a copy of the last indexed member of the CellTable, or the bounding cell. -- it holds the col and row of the bounding cell print("BoundingCell prints below") print\_r.print\_r(BoundingCell) --let's print out the table so you can see the col and row of the bounding cell

In case you’ve forgotten, the “State” variable in the code is always the current Player’s color.  So if you add a print statement anywhere in the code, you can always get the current Player’s color or State.

print("State == ",State") --this will display the current Player's color

You need to verify in a conditional statement, the bounding cell on the game board table T[BoundingCell.col][BoundingCell.row].state == State is met before any cells from the CellTable are added to the CaptureTable.  Remember, if a cell is added to the CaptureTable, it will be flipped with no further checks for it’s validity.

if "you fill in the conditional statement" then --if the conditional statement is met, then add cells to the CaptureTable for i = 1, #CellTable do --starting near cell in play, put all Cells above of opposite color into a CaptureTable if T[CellTable[i].col][CellTable[i].row].state ~= State and T[CellTable[i].col][CellTable[i].row].state ~= "blank" then \_index = #CaptureTable + 1 CaptureTable[\_index] = {} CaptureTable[\_index].col = Col CaptureTable[\_index].row = Row elseif T[CellTable[i].col][CellTable[i].row].state == State then --when a cell with the same color is found, stop adding cells to CaptureTable print("break--cell matches State color") break end end print("\*\*\*Up\_Right vector / CaptureTable prints below") print\_r.print\_r(CaptureTable) end

Nail