Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.01 KB | None | 0 0
  1. object SquaresWithOne1Rule extends SlitherlinkRule {
  2.       def isMatch(x:Int, y:Int, req:Char): Boolean = {
  3.         return req == '1' && x > 0 && (x - 1) < width && y > 0 && (y - 1) < height
  4.       }
  5.  
  6.       def apply (x:Int, y:Int, req:Char): Unit = {
  7.         if (hasWall(x - 1, y, Direction.North) && blacklist.contains((x - 1, y - 1, Direction.East))) {
  8.           blacklist = blacklist :+ (x, y, Direction.South)
  9.           blacklist = blacklist :+ (x, y, Direction.East)
  10.         }
  11.         if (hasWall(x + 1, y, Direction.North) && blacklist.contains((x + 1, y - 1, Direction.West))) {
  12.           blacklist = blacklist :+ (x, y, Direction.South)
  13.           blacklist = blacklist :+ (x, y, Direction.West)
  14.         }
  15.         if (hasWall(x - 1, y, Direction.South) && blacklist.contains((x - 1, y + 1, Direction.East))) {
  16.           blacklist = blacklist :+ (x, y, Direction.North)
  17.           blacklist = blacklist :+ (x, y, Direction.West)
  18.         }
  19.         if (hasWall(x + 1, y, Direction.South) && blacklist.contains((x + 1, y - 1, Direction.West))) {
  20.           blacklist = blacklist :+ (x, y, Direction.North)
  21.           blacklist = blacklist :+ (x, y, Direction.East)
  22.         }
  23.       }
  24.  
  25.       def unapply (x:Int, y:Int, req:Char): Unit = {
  26.         blacklist = blacklist.filter(_ != (x, y, Direction.East))
  27.         blacklist = blacklist.filter(_ != (x, y, Direction.West))
  28.         blacklist = blacklist.filter(_ != (x, y, Direction.South))
  29.         blacklist = blacklist.filter(_ != (x, y, Direction.North))
  30.       }
  31.     }
  32.  
  33.     object SquaresWithOne2Rule extends SlitherlinkRule {
  34.       def isMatch(x:Int, y:Int, req:Char): Boolean = {
  35.         return req == '1' && x > 0 && (x - 1) < width && y > 0 && (y - 1) < height
  36.       }
  37.  
  38.       def apply (x:Int, y:Int, req:Char): Unit = {
  39.         if (hasWall(x - 1, y, Direction.North) && blacklist.contains((x, y, Direction.East)) && blacklist.contains((x, y, Direction.South))) {
  40.           blacklist = blacklist :+ (x - 1, y - 1, Direction.East)
  41.         }
  42.         if (hasWall(x + 1, y, Direction.North) && blacklist.contains((x, y, Direction.West)) && blacklist.contains((x, y, Direction.South))) {
  43.           blacklist = blacklist :+ (x + 1, y - 1, Direction.West)
  44.         }
  45.         if (hasWall(x - 1, y, Direction.South) && blacklist.contains((x, y, Direction.East)) && blacklist.contains((x, y, Direction.North))) {
  46.           blacklist = blacklist :+ (x - 1, y + 1, Direction.East)
  47.         }
  48.         if (hasWall(x + 1, y, Direction.South) && blacklist.contains((x, y, Direction.West)) && blacklist.contains((x, y, Direction.North))) {
  49.           blacklist = blacklist :+ (x + 1, y + 1, Direction.West)
  50.         }
  51.       }
  52.  
  53.       def unapply (x:Int, y:Int, req:Char): Unit = {
  54.         blacklist = blacklist.filter(_ != (x - 1, y - 1, Direction.East))
  55.         blacklist = blacklist.filter(_ != (x + 1, y - 1, Direction.West))
  56.         blacklist = blacklist.filter(_ != (x - 1, y + 1, Direction.East))
  57.         blacklist = blacklist.filter(_ != (x + 1, y + 1, Direction.West))
  58.       }
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement