Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object SquaresWithOne1Rule extends SlitherlinkRule {
- def isMatch(x:Int, y:Int, req:Char): Boolean = {
- return req == '1' && x > 0 && (x - 1) < width && y > 0 && (y - 1) < height
- }
- def apply (x:Int, y:Int, req:Char): Unit = {
- if (hasWall(x - 1, y, Direction.North) && blacklist.contains((x - 1, y - 1, Direction.East))) {
- blacklist = blacklist :+ (x, y, Direction.South)
- blacklist = blacklist :+ (x, y, Direction.East)
- }
- if (hasWall(x + 1, y, Direction.North) && blacklist.contains((x + 1, y - 1, Direction.West))) {
- blacklist = blacklist :+ (x, y, Direction.South)
- blacklist = blacklist :+ (x, y, Direction.West)
- }
- if (hasWall(x - 1, y, Direction.South) && blacklist.contains((x - 1, y + 1, Direction.East))) {
- blacklist = blacklist :+ (x, y, Direction.North)
- blacklist = blacklist :+ (x, y, Direction.West)
- }
- if (hasWall(x + 1, y, Direction.South) && blacklist.contains((x + 1, y - 1, Direction.West))) {
- blacklist = blacklist :+ (x, y, Direction.North)
- blacklist = blacklist :+ (x, y, Direction.East)
- }
- }
- def unapply (x:Int, y:Int, req:Char): Unit = {
- blacklist = blacklist.filter(_ != (x, y, Direction.East))
- blacklist = blacklist.filter(_ != (x, y, Direction.West))
- blacklist = blacklist.filter(_ != (x, y, Direction.South))
- blacklist = blacklist.filter(_ != (x, y, Direction.North))
- }
- }
- object SquaresWithOne2Rule extends SlitherlinkRule {
- def isMatch(x:Int, y:Int, req:Char): Boolean = {
- return req == '1' && x > 0 && (x - 1) < width && y > 0 && (y - 1) < height
- }
- def apply (x:Int, y:Int, req:Char): Unit = {
- if (hasWall(x - 1, y, Direction.North) && blacklist.contains((x, y, Direction.East)) && blacklist.contains((x, y, Direction.South))) {
- blacklist = blacklist :+ (x - 1, y - 1, Direction.East)
- }
- if (hasWall(x + 1, y, Direction.North) && blacklist.contains((x, y, Direction.West)) && blacklist.contains((x, y, Direction.South))) {
- blacklist = blacklist :+ (x + 1, y - 1, Direction.West)
- }
- if (hasWall(x - 1, y, Direction.South) && blacklist.contains((x, y, Direction.East)) && blacklist.contains((x, y, Direction.North))) {
- blacklist = blacklist :+ (x - 1, y + 1, Direction.East)
- }
- if (hasWall(x + 1, y, Direction.South) && blacklist.contains((x, y, Direction.West)) && blacklist.contains((x, y, Direction.North))) {
- blacklist = blacklist :+ (x + 1, y + 1, Direction.West)
- }
- }
- def unapply (x:Int, y:Int, req:Char): Unit = {
- blacklist = blacklist.filter(_ != (x - 1, y - 1, Direction.East))
- blacklist = blacklist.filter(_ != (x + 1, y - 1, Direction.West))
- blacklist = blacklist.filter(_ != (x - 1, y + 1, Direction.East))
- blacklist = blacklist.filter(_ != (x + 1, y + 1, Direction.West))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement