Skip to content

Commit

Permalink
Update paperArtist.lua (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
User670 authored Dec 21, 2023
1 parent 0ad8fab commit 14495d7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions assets/ai/paperArtist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ local function simulateDrop(field,cb,cx)
return math.max(unpack(delta))+1,delta
end

function paperArtist.calculateFieldScore(field,cb,cy)
function paperArtist.calculateFieldScore(field,cb,cx,cy)
local clear=0


-- Place the piece into the field
for y=1,#cb do
-- If this line doesn't exist, create an all-false line
if not field[y+cy-1] then
field[y+cy-1]=TABLE.new(false,10)
end
for x=1,#cb[1] do
field[y+cy-1][x+cx-1]=field[y+cy-1][x+cx-1] or cb[y][x]
end
end

-- Clear filled lines
for y=cy+#cb-1,cy,-1 do
if field[y] then
Expand All @@ -41,7 +52,7 @@ function paperArtist.calculateFieldScore(field,cb,cy)

-- Which boy can refuse AC?
if #field==0 then
return 1e99
return 1e99,0,0
end

local rowB=0
Expand Down Expand Up @@ -82,8 +93,7 @@ function paperArtist.findPosition(field,shape)
local F=TABLE.shift(field,1)
local cy,colH=simulateDrop(F,shape,cx)
local score=0

local clear,rowB,colB=paperArtist.calculateFieldScore(field,shape,cy)
local clear,rowB,colB=paperArtist.calculateFieldScore(F,shape,cx,cy)
score=score+clear*2-rowB*3-colB*2
score=score-cy
local minH=math.min(unpack(colH))
Expand Down

0 comments on commit 14495d7

Please sign in to comment.