You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- The Spear (very simple, easy to counter)-- Strategy: -- We place a large vertical wall down the middle of the playing field. ¨-- While doing this, the opponent will walk down one side of the wall. We will walk down the same and block off behind us,-- making the opponent walk a longer distance to their end goal and lose. If the spear is disrupted, -- we do our best to still create a spear, although a slightly destroyed one. -- Notes:-- Walls required down the middle: 4-- Walls to block off one side: 2-- context.board[x + y*9 + 1] to get coordinates-- Specifics:-- The first 3 turns we place a wall-- The 4th turn we pick a side at random if the enemy haven't picke one, otherwise we pick the same side as the enemy-- The 5th turn we block off the final part of the middle, aka finising the spear-- The following 4 turns we walk the shortest path to victory (Turn 6-9)-- The following 2 turns we block off the enemy (Turn 10-11)-- After that, we just walk the shortest path to victory (Turn 12+)require"math"-- Functions:functionOnBoard(x, y)
returnx+y*9+1>0andx+y*9+1<=81end-- Pathing functionsfunctionUpdateNearbyTiles(board, x, y, pathLength)
localupdate=false-- one for each directionifOnBoard(x+1, y) thenifpathLength>board[x+y*9+2] orboard[x+y*9+2] ==0thenboard[x+y*9+2] =pathLengthupdate=trueendendifOnBoard(x-1, y) thenifpathLength>board[x+y*9] orboard[x+y*9] ==0thenboard[x+y*9] =pathLengthupdate=trueendendifOnBoard(x, y+1) thenifpathLength>board[x+y*9+10] orboard[x+y*9+10] ==0thenboard[x+y*9+10] =pathLengthupdate=trueendendifOnBoard(x, y-1) thenifpathLength>board[x+y*9-8] orboard[x+y*9-8] ==0thenboard[x+y*9-8] =pathLengthupdate=trueendendreturnupdateendfunctionGetSmallestNearby(board, x, y)
localsmallest=-100ifOnBoard(x+1, y) thenifboard[x+y*9+2] >smallestandboard[x+y*9+2] <0thensmallest=board[x+y*9+2]
endendifOnBoard(x-1, y) thenifboard[x+y*9] >smallestandboard[x+y*9+2] <0thensmallest=board[x+y*9]
endendifOnBoard(x, y+1) thenifboard[x+y*9+10] >smallestandboard[x+y*9+2] <0thensmallest=board[x+y*9+10]
endendifOnBoard(x, y-1) thenifboard[x+y*9-8] >smallestandboard[x+y*9+2] <0thensmallest=board[x+y*9-8]
endendreturnsmallestendfunctionPathFromTile(board, x, y)
ifboard[x+y*9+1] ==0thenreturnfalseendlocalpathLength=board[x+y*9+1] -1localupdate=UpdateNearbyTiles(board, x, y, pathLength)
-- update jump, Edgecase I don't take into consideration, too specific:-- player 2 in a top corner, a wall next to player 2 and player 1 one step down from player 2.ifboard[x+y*9+1] ==2thenlocaljumpPathLength=GetSmallestNearby(board, x, y) -1ifnotupdatethenupdate=UpdateNearbyTiles(board, x, y, jumpPathLength)
elseUpdateNearbyTiles(board, x, y, jumpPathLength)
endendreturnupdateendfunctionMapPaths(context)
-- pathfinder function-- not sure if it's best to start from where the player is or from where the player wants to go-- I think it's best to start from where the player wants to go.-- How it works:-- the amount of steps required is -1 * value, so we don't interfere with where everything is-- we start by making all 0-values in y=0 to 1-- we then iterate through the board along the y-directions as long as we change any paths.-- each number adds (subtracts bcs negative values) one to itself and sets each tile next to it to-- that value if that value is smaller (close to zero/larger) than the value currently on the tile.-- max iterations/calculations should be roughly 4*81*81 ~ 26000. expected amount of iterations is roughly 4*9*2*81 ~6400localboard=context.boardfori=0,8doifboard[i+1] ==0thenboard[i+1] =-1endendlocalchange=truewhilechangedochange=falsefori=0,8doforj=0,8dolocalupdate=PathFromTile(board, i, j)
ifnotchangeandupdatethenchange=trueendendendendendfunctionWalkShortestPath(context)
MapPaths(context)
localboard=context.boardlocalx=context.player.xlocaly=context.player.ylocalsmallest=GetSmallestNearby(board, x, y)
PrevContext=contextifOnBoard(x+1, y) thenifboard[x+y*9+2] ==smallestthenreturn"1"endendifOnBoard(x-1, y) thenifboard[x+y*9] ==smallestthenreturn"3"endendifOnBoard(x, y+1) thenifboard[x+y*9+10] ==smallestthenreturn"2"endendifOnBoard(x, y-1) thenifboard[x+y*9+10] ==smallestthenreturn"0"endendend-- Spear wall functionfunctionCheckOneSpearGap(y, context) -- returns flags for if left or right is freereturn (notSTD__OCCUPIED(context, 3, y) andnotSTD__OCCUPIED(context, 4, y)) +2*(notSTD__OCCUPIED(context, 4, y) andnotSTD__OCCUPIED(context, 5, y))
endfunctionPlaceSpearLeft(y)
return"3," ..tostring(y) ..",4," ..tostring(y)
endfunctionPlaceSpearRight(y)
return"4," ..tostring(y) ..",5," ..tostring(y)
endfunctionPlaceSpearRandomDirection(y)
localrand=math.floor(math.random() +0.5)
ifrand==0thenreturnPlaceSpearLeft(y)
endreturnPlaceSpearRight(y)
endfunctionPlaceSpearWall(y_start, context)
ify_start>8thenreturnWalkShortestPath(context) -- all spear walls placed/a player is in the way. end-- Step 1: Check if both wall positions are available. If so, place wallif ((notSTD__OCCUPIED(context, 4, y_start)) and (notSTD__OCCUPIED(context, 4, y_start+1))) thenreturn"4," ..tostring(y_start) ..",4," ..tostring(y_start+1)
end-- Step 2: Check if both wall positions are occupied. If so, place the next SpearWallif (STD__OCCUPIED(context, 4, y_start) andSTD__OCCUPIED(context, 4, y_start+1)) thenreturnPlaceSpearWall(y_start+2, context)
end-- Step 3: Check if it's possible to fill the 1-gap with a walllocaldirTable= {
[1] =PlaceSpearLeft,
[2] =PlaceSpearRight,
[3] =PlaceSpearRandomDirection
}
localdirection=CheckOneSpearGap(y_start, context)
ifdirection>0thenreturndirTable[direction](y_start)
enddirection=CheckOneSpearGap(y_start+1, context)
ifdirection>0thenreturndirTable[direction](y_start)
endreturnPlaceSpearWall(y_start+2, context)
end-- Functions for side and walling off one sidesfunctionDetermineEnemySide(context)
localenemy_x=context.opponent.xifenemy_x<4thenEnemySide=-1endifenemy_x>4thenEnemySide=1endifenemy_x==4thenEnemySide=0endendfunctionPlaceHorizontalWall(x, context)
-- If we cannot place another wallifx>7orx<1thenreturnWalkShortestPath(context)
end-- Step 1: Check if both wall positions are available. If so, place wallif (notSTD__OCCUPIED(context, x, 0)) andnotSTD__OCCUPIED(context, x+1, 0) thenreturntostring(x) ..",0," ..tostring(x+1) ..",0"end-- Step 2: Check if both wall positions are occupied. If so, place the next Horizontal wallifSTD__OCCUPIED(context, x, 0) andSTD__OCCUPIED(context, x+1, 0) thenreturnPlaceHorizontalWall(x+2, context)
end-- Step 3: Check if there is a wall-spot free, otherwise It's blocked and we can place the next Horizontal wallif (notSTD__OCCUPIED(context, x, 0)) andnotSTD__OCCUPIED(context, x, 1) thenreturntostring(x) ..",0," ..tostring(x) ..",1"endif (notSTD__OCCUPIED(context, x+1, 0)) andnotSTD__OCCUPIED(context, x+1, 1) thenreturntostring(x+1) ..",0," ..tostring(x+1) ..",1"endreturnPlaceHorizontalWall(x+2*EnemySide, context)
end-- Turn functionsfunctionTurnOneTwoThree(context)
ifSpearWalls>=3then-- all the walls have been placedreturnTurnFour(context)
endlocalenemy_y=context.opponent.ySpearWalls=SpearWalls+1returnPlaceSpearWall(enemy_y+SpearWalls*2-1, context)
endfunctionTurnFour(context)
ifnotEnemySide==0then-- our player should already have moved out of the way, so we can place the final wall 1 turn earlierreturnTurnFive(context)
endDetermineEnemySide(context)
localx=context.player.xlocaly=context.player.yifnotEnemySide==0thenifnotSTD__OCCUPIED(context, x+EnemySide, y) thenreturntostring(2-EnemySide)
endendreturnWalkShortestPath(context)
endfunctionTurnFive(context)
returnPlaceSpearWall(7, context)
endfunctionWallOffEnemy(context)
-- no need to stress with walling off horizontallyifcontext.opponent.y>4thenDetermineEnemySide(context)
SideDetermined=trueendifSideDeterminedandHorizontalWalls<2thenHorizontalWalls=HorizontalWalls+1returnPlaceHorizontalWall(4-EnemySide+EnemySide*2*HorizontalWalls, context)
endWalkShortestPath(context)
end-- Variables Turn=1WentFirst=falseEnemySide=0SideDetermined=falseWalls=10SpearWalls=0HorizontalWalls=0PreparationTurns=10PrevContext=nilActionTable= {
[1] =TurnOneTwoThree,
[2] =TurnOneTwoThree,
[3] =TurnOneTwoThree,
[4] =TurnFour,
[5] =TurnFive,
[6] =WalkShortestPath,
[7] =WalkShortestPath,
[8] =WalkShortestPath,
[9] =WalkShortestPath,
[10] =WallOffEnemy,
}
-- onTurn-- doesn't follow my vscode addon's naming conventions >-<functiononTurn(context)
localfunc=ActionTable[Turn]
ifnotTurn==PreparationTurnsthenTurn=Turn+1endreturnfunc(context)
end-- onJumpfunctiononJump(context)
context=PrevContextlocalboard=context.boardlocalx=context.opponent.xlocaly=context.opponent.ylocalsmallest=GetSmallestNearby(board, x, y)
ifOnBoard(x+1, y) thenifboard[x+y*9+2] ==smallestthenreturn"1"endendifOnBoard(x-1, y) thenifboard[x+y*9] ==smallestthenreturn"3"endendifOnBoard(x, y+1) thenifboard[x+y*9+10] ==smallestthenreturn"2"endendifOnBoard(x, y-1) thenifboard[x+y*9+10] ==smallestthenreturn"0"endendend
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: