-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvariant.lua
92 lines (75 loc) · 2.11 KB
/
variant.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- variant, base class for all variants, implements fallback behaviour
local log = require 'log'
local Util = require 'util'
---@class Variant
---@field Wikipedia string
local Variant = {}
Variant.__index = Variant
function Variant.new(o)
o = o or {}
o.wikipedia='https://en.wikipedia.org/wiki/Patience_(game)'
return setmetatable(o, Variant)
end
function Variant:buildPiles()
log.error('base function should not be called')
end
function Variant:startGame()
log.error('base function should not be called')
end
function Variant:afterMove()
-- do nothing if variant does not implement this
end
function Variant:moveTailError(tail)
log.error('base function should not be called')
return nil
end
---@return string|nil
function Variant:tailAppendError(dst, tail)
log.error('base function should not be called')
return nil
end
---@return integer
function Variant:unsortedPairs(pile)
log.error('base function should not be called')
return 0
end
---@return number
function Variant:percentComplete()
-- default percentComplete behaviour
-- variants (eg Accordian) can override this
local pairs = 0
local unsorted = 0
for _, p in ipairs(_G.BAIZE.piles) do
if #p.cards > 1 then
pairs = pairs + (#p.cards - 1)
unsorted = unsorted + p:unsortedPairs()
end
end
return 100 - Util.mapValue(unsorted, 0, pairs, 0, 100)
end
---@return boolean
function Variant:complete()
-- trigger the default behaviour
-- variants (eg Accordian) can override this
return _G.BAIZE:complete()
end
-- there is no default for pileTapped
-- it's up to each variant to implement this
-- pileTapped on a Stock pile will usually recycle Waste cards to Stock
-- in Spider it just displays a message
function Variant:tailTapped(tail)
tail[1].parent:tailTapped(tail)
end
---default behaviour for cardSelected;
---return false means 'script did nothing'
---return true means 'script handled this COMPLETELY'
---@param card Card
---@return boolean
function Variant:cardSelected(card)
return false
end
---return command line name for fc-solver, see https://fc-solve.shlomifish.org/docs/distro/USAGE.html
function Variant:fcSolver()
return ''
end
return Variant