From 14495d769b8a4e16c18d4a1a9fa688c5e9dc82c9 Mon Sep 17 00:00:00 2001 From: User670 <22617255+User670@users.noreply.github.com> Date: Thu, 21 Dec 2023 23:49:32 +0800 Subject: [PATCH] Update paperArtist.lua (#25) --- assets/ai/paperArtist.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/assets/ai/paperArtist.lua b/assets/ai/paperArtist.lua index 586b2067..8ededfba 100644 --- a/assets/ai/paperArtist.lua +++ b/assets/ai/paperArtist.lua @@ -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 @@ -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 @@ -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))