Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.43 KB | None | 0 0
  1.   def isBoatBuilt(boat:List[Square], boardSize:Int, usage:String):Boolean = {
  2.     //Check for boat of size 1 (one boat-tile is surrounded by water)
  3.     if(boat.length == 1){
  4.       if(boat.head.getNeighbours(boardSize).forall((n:String) => n == "-")) return true
  5.     }
  6.  
  7.     else {
  8.       val headNeighbours = boat.head.getNeighbours(boardSize)
  9.       val lastNeighbours = boat.last.getNeighbours(boardSize)
  10.      
  11.       if (usage == "built") {
  12.         //Check for horizontal boat
  13.         //Head -> left tile = water, right tile = boat, Last -> left tile = boat, right tile = water
  14.         if (headNeighbours(2) == "-" && headNeighbours.head == "S"
  15.           && lastNeighbours(2) == "S" && lastNeighbours.head == "-") return true
  16.        
  17.         //Check for vertical boat
  18.         //Head -> upper tile = water, lower tile = boat, Last -> upper tile = boat, lower tile = water
  19.         if (headNeighbours(3) == "-" && headNeighbours(1) == "S"
  20.           && lastNeighbours(3) == "S" && lastNeighbours(1) == "-") return true
  21.        
  22.       } else if (usage == "finished") {
  23.         //Horizontal
  24.         if (headNeighbours(2) == "-" && headNeighbours.head != "?"
  25.           && lastNeighbours(2) != "?" && lastNeighbours.head == "-") return true
  26.        
  27.         //Vertical
  28.         if (headNeighbours(3) == "-" && headNeighbours(1) != "?"
  29.           && lastNeighbours(3) != "?" && lastNeighbours(1) == "-") return true
  30.       }
  31.     }
  32.     false
  33.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement