Anonymous user
2048: Difference between revisions
bugfix: moving just a 2 onto a 2* not a valid move
(moved comment to avoid potential confusion) |
(bugfix: moving just a 2 onto a 2* not a valid move) |
||
Line 117:
}
# Put a "2
proc spawn-new {} {
set emptyCell [pick [empty [cell-indexes]]]
if {[llength $emptyCell] > 0} {
forcells [list $emptyCell] i j cell {
set cell 2
}
}
return $emptyCell
}
Line 145:
set newIndex [vector-add "$i $j" $directionVect]
set removedStar 0
if {$cell eq {2*}} {▼
set cell 2▼
# For every nonempty source cell and valid destination cell...
if {$cell != 0 && [valid-cell? $newIndex]} {
if {[cell-get $newIndex] == 0} {
# Destination is empty.
if {$checkOnly} {
# -level 2 is to return from both forcells and move-all.
Line 166 ⟶ 161:
} elseif {([cell-get $newIndex] eq $cell) &&
[string first + $cell] == -1} {
# Destination is the same number as source.
if {$checkOnly} {
return -level 2 true
Line 178 ⟶ 173:
}
}
}
}
Line 223 ⟶ 214:
}
# Pretty-print the board. Specify an index in highlight to highlight a cell.
proc print-board {{highlight {-1 -1}}} {
forcells [cell-indexes] i j cell {
if {$j == 0} {
Line 231 ⟶ 222:
puts -nonewline [
if {$cell != 0} {
format "\[%4s\]" $cell*
format "\[%4s\]" $cell
} else {
lindex "......"
Line 264 ⟶ 260:
set possibleMoves {}
# Add new tile to the board and print the board highlighting this tile.
print-board [spawn-new]
check-win
|