The scheme basically works. It’s not complete and even the Up block needs more work, but it’s a good start.
Here’s the start of the validPlay(col, row, state) , paste it above the grid() so it is in scope.
Right now it only works on the Up vector, it works when you select T[5][6] after startup. This block of code will still need to be modified to make sure there are no cells in the table that are beyond the game board. It will also need to make sure a vector is bound by chip with the color in play at the opposite end of the vector.
Your project now is up to you to complete the validPlay() for the remaining 7 possible vectors using the Up code as a template.
Remember, work in a clockwise direction through the vectors, it will be easier for me to follow your code that way.
Post your code as you complete each vector please.
Here ya go…
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 Col \> 0 and Col \< 9 and Row \> 0 and Row \< 9 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") PrintReadableTables.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") PrintReadableTables.print\_r(CaptureTable) end end ----------end Up vector code --next vector code goes here and so on ------- return CaptureTable -- return the CaptureTable back to gridTapped(event) end
Nail