more debugging printouts
This commit is contained in:
@@ -35,10 +35,13 @@ struct Map: CustomStringConvertible {
|
||||
var s: [[String]] = Array(
|
||||
repeating: Array(repeating: " ", count: w*2), count: h
|
||||
)
|
||||
walls.forEach { w in s[w.y][w.x] = "██" }
|
||||
boxes.forEach { b in s[b.y][b.x] = "▒▒" }
|
||||
s[bot.y][bot.x] = "🯅🯅"
|
||||
return s.map { row in row.joined() }.joined(separator: "\n")
|
||||
walls.forEach { w in s[w.y][w.x] = "🮘🮘" }
|
||||
boxes.forEach { b in s[b.y][b.x] = "🬴🬸" }
|
||||
s[bot.y][bot.x] = "\u{001B}[91m🮿 \u{001B}[0m"
|
||||
return (" " + (0..<w).map { " \($0 % 10)" }.joined() + "\n") +
|
||||
s.enumerated().map {
|
||||
i, row in String(format: "%3d ", i) + row.joined()
|
||||
}.joined(separator: "\n")
|
||||
}
|
||||
var gps: Int { return boxes.reduce(0) { s, box in s + box.gps } }
|
||||
|
||||
@@ -67,13 +70,9 @@ struct Map: CustomStringConvertible {
|
||||
next = next.move(dir)
|
||||
}
|
||||
if !walls.contains(next) {
|
||||
if !pushes.isEmpty { print("pushing box \(pushes)") }
|
||||
pushes.forEach { boxes.remove($0) }
|
||||
pushes.forEach { boxes.insert($0.move(dir)) }
|
||||
bot = bot.move(dir)
|
||||
print("moving bot to \(bot)")
|
||||
} else {
|
||||
print("noop")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +89,7 @@ var (map, moves) = try readInput(CommandLine.arguments[1])
|
||||
print(map)
|
||||
print(moves)
|
||||
for move in moves {
|
||||
print(move)
|
||||
//print(move)
|
||||
map.move(move)
|
||||
}
|
||||
print(map)
|
||||
|
Reference in New Issue
Block a user