type logic

This commit is contained in:
Alexander Yakovlev 2024-04-28 11:55:40 +06:00
parent 447f8e0f42
commit f603ebda4f
Signed by: oreolek
GPG key ID: 8269E24B4008E32A
3 changed files with 49 additions and 21 deletions

View file

@ -13,7 +13,9 @@
~ return x
=== function lastcard(ref list)
~ return LIST_MIN(list)
{ !x: ~ return "" }
~ temp x = LIST_MIN(list)
~ return x
=== function is_clubs(x)
~ return (x == two_of_clubs || x == three_of_clubs || x == four_of_clubs || x == five_of_clubs || x == six_of_clubs || x == seven_of_clubs || x == eight_of_clubs || x == nine_of_clubs || x == ten_of_clubs || x == jack_of_clubs || x == queen_of_clubs || x == king_of_clubs || x == ace_of_clubs)
@ -60,6 +62,8 @@
=== function tonumber(x)
{
- x == ():
~ return 0
- is_two(x):
~ return 2
- is_three(x):
@ -103,17 +107,30 @@
~ return follows(x,y)
}
=== function can_move_to_full(ref col)
=== function can_move_to_foundation(ref col)
~ temp x = lastcard(col)
~ temp y = ""
{
- is_spades(x):
~ y = lastcard(full1)
~ y = lastcard(foundation1)
- is_diamonds(x):
~ y = lastcard(full2)
~ y = lastcard(foundation2)
- is_clubs(x):
~ y = lastcard(full3)
~ y = lastcard(foundation3)
- is_hearts(x):
~ y = lastcard(full4)
~ y = lastcard(foundation4)
}
~ return follows(x,y)
=== function can_move_to_empty(ref col, ref empty)
{col == () || empty != ():
~ return false
}
~ return true
=== function can_move_to_col(ref column_one, ref column_two)
~ temp x = lastcard(column_one)
~ temp y = lastcard(column_two)
{!x: ~ return false}
{!y:~ return true}
~ return (( (!is_black(x) && is_black(y)) || (is_black(x) && !is_black(y)) ) && follows(y,x) )

View file

@ -14,10 +14,10 @@ VAR col8 = ()
VAR empty1 = ()
VAR empty2 = ()
VAR full1 = ()
VAR full2 = ()
VAR full3 = ()
VAR full4 = ()
VAR foundation1 = ()
VAR foundation2 = ()
VAR foundation3 = ()
VAR foundation4 = ()
// Put 7 random cards to slot 1
~ col1 += randomcard(cards)
@ -87,10 +87,10 @@ VAR full4 = ()
<div id="playing_field"> <>
<div id="empty1" class="cardempty">{empty1}</div> <>
<div id="empty2" class="cardempty">{empty2}</div> <>
<div id="full1" class="cardstack">{full1}</div> <>
<div id="full2" class="cardstack">{full2}</div> <>
<div id="full3" class="cardstack">{full3}</div> <>
<div id="full4" class="cardstack">{full4}</div> <>
<div id="foundation1" class="cardstack">{foundation1}</div> <>
<div id="foundation2" class="cardstack">{foundation2}</div> <>
<div id="foundation3" class="cardstack">{foundation3}</div> <>
<div id="foundation4" class="cardstack">{foundation4}</div> <>
<div id="col1" class="cardcolumn">{col1}</div> <>
<div id="col2" class="cardcolumn">{col2}</div> <>
<div id="col3" class="cardcolumn">{col3}</div> <>
@ -101,12 +101,11 @@ VAR full4 = ()
<div id="col8" class="cardcolumn">{col8}</div> <>
</div>
+ {empty1 == () && col1 != ()} Move {lastcard(col1)} from col1 to empty1
-> move_from_col1_to_empty1
+ {empty2 == () && col1 != ()} Move {lastcard(col1)} from col1 to empty2
-> move_from_col1_to_empty2
-> END
+ {can_move_to_empty(col1, empty1)} [Move {lastcard(col1)} to empty space] -> move_from_col1_to_empty1
+ {empty1 != () && can_move_to_empty(col1, empty2)} [Move {lastcard(col1)} to empty space] -> move_from_col1_to_empty2
+ {can_move_to_col(empty1, col1)} [Move {lastcard(empty1)} to col1] -> move_from_empty1_to_col1
+ {can_move_to_col(empty2, col1)} [Move {lastcard(empty2)} to col1] -> move_from_empty2_to_col1
+ -> END
=== move_from_col1_to_empty1
@ -119,3 +118,15 @@ VAR full4 = ()
~ empty2 += pop(col1)
-> main
=== move_from_empty1_to_col1
~ col1 += pop(empty1)
-> main
=== move_from_empty2_to_col1
~ col1 += pop(empty2)
-> main

View file

@ -270,7 +270,7 @@ body {
}
}
@for $i from 1 through 4 {
#full#{$i} {
#foundation#{$i} {
right: ($card_width * ($i - 1) + ($gutter / 2));
}
}