-
Notifications
You must be signed in to change notification settings - Fork 0
/
fire_bomb_probe.scala
80 lines (60 loc) · 1.9 KB
/
fire_bomb_probe.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import scala.util.Random
val random = new Random
case class Position(x: Int, y: Int)
def random2DimArray(dim1: Int, dim2: Int) =
Array.fill(dim1, dim2){random.nextInt(2)}
val data = random2DimArray(12, 15)
var players = collection.mutable.Map.empty[String, Position]
def swap = players.map(_.swap)
/*("p1" -> (1,0),
"p2"->(1,1), "p3"->(1,3), "p4"->(1,4), "p5"->(1,5),
"p2.2"->(2,1), "p3.2"->(2,3), "p4.2"->(2,4), "p5.2"->(2,5),
"p2.3"->(3,1), "p3.3"->(3,3), "p4.3"->(3,4), "p5.3"->(3,5),
"p2.4"->(4,1), "p3.4"->(4,3), "p4.4"->(4,4), "p5.4"->(4,5),
"p2.5"->(5,1), "p3.5"->(5,3), "p4.5"->(5,4), "p5.5"->(5,5))
*/
def posList(pos: Position) = List[Position](pos)
var pl = players.values.toList
def randomPosition :Position = {
val pos = new Position(random.nextInt(11), random.nextInt(14))
if(data(pos.x)(pos.y).equals(1)) {
if (pl.contains(posList(pos))) randomPosition else pos
} else randomPosition
}
def addPlayer(user: String) = players += (user -> randomPosition)
def check (list: List[Position]) = {
if(!list.isEmpty){
val buffer = new collection.mutable.ListBuffer[String]()
for(lis <- list if pl.contains(lis)) {
buffer += swap(lis)
}
val li = buffer.toList
println(li)
}
}
def bomb(pos: Position) = {
val buffer = new collection.mutable.ListBuffer[Position]
for (i <- pos.x - 2 to pos.x + 2){
buffer += Position(i , pos.y)
//println(listX)
//if(pl.contains(listX.head)) println("bingo x " + swap(listX.head))
}
for (i <- pos.y - 2 to pos.y + 2){
buffer += Position(pos.x , i)
//if(pl.contains(listY.head)) println("bingo y " + swap(listY.head))
}
val list = buffer.distinct.toList
println(list)
check(list)
}
def users = for(i <- 0 until 15) addPlayer("p" + i.toString)
users
def li = pl
def liDi = li.distinct
bomb(Position(9,4))
check(List(Position(9,4)))
addPlayer("u")
println(players)
println(li)
println(liDi)
swap(Position(8,10))