public void unfoldByPlaneAt(int pos) { MirrorPlane p = planes[pos]; planes.RemoveAt(pos); int nPlanes = planes.Count; for (int i = 0; i < nPlanes; i++) { planes.Add(planes[i].flipBy(p)); } int nPlayers = players.Count; for (int i = 0; i < nPlayers; i++) { Player newPlayer = new Player(players[i].X, players[i].Y); newPlayer.flipBy(p); /*foreach (MirrorPlane mp in players[i].crosedPlanes) * { * newPlayer.crosedPlanes.Add(mp.flipBy(p)); * }*/ newPlayer.crosedPlanes.Add(p); players.Add(newPlayer); } }
public void flipBy(MirrorPlane p) { if (p.isHorizontal()) { this.Y = p.Y1 - (this.Y - p.Y1); } else { this.X = p.X1 - (this.X - p.X1); } }
public MirrorPlane flipBy(MirrorPlane p) { if (p.isHorizontal()) { return(new MirrorPlane(this.X1, p.Y1 - (this.Y1 - p.Y1), this.X2, p.Y1 - (this.Y2 - p.Y1))); } else { return(new MirrorPlane(p.X1 - (this.X1 - p.X1), this.Y1, p.X1 - (this.X2 - p.X1), this.Y2)); } }
public static MirrorPlane join(MirrorPlane mp1, MirrorPlane mp2) { return(new MirrorPlane(Math.Min(mp1.X1, mp2.X1), Math.Min(mp1.Y1, mp2.Y1), Math.Max(mp1.X2, mp2.X2), Math.Max(mp1.Y2, mp2.Y2))); }
public void joinPlanes() { bool unjoinable = false; while (!unjoinable) { unjoinable = true; for (int i = 0; i < planes.Count; i++) { for (int j = i + 1; j < planes.Count; j++) { if ( (planes[i].X1 == planes[j].X1) && (planes[i].Y1 == planes[j].Y1) && (planes[i].X2 == planes[j].X2) && (planes[i].Y2 == planes[j].Y2) ) { planes.RemoveAt(j); planes.RemoveAt(i); unjoinable = false; break; } } if (!unjoinable) { break; } } if (unjoinable) { for (int i = 0; i < planes.Count; i++) { for (int j = i + 1; j < planes.Count; j++) { if ( ( planes[i].isHorizontal() == planes[j].isHorizontal() ) && ( ( planes[i].isHorizontal() && planes[i].Y1 == planes[j].Y1 && planes[i].X1 <= planes[j].X2 && planes[i].X2 >= planes[j].X1 ) || ( !planes[i].isHorizontal() && planes[i].X1 == planes[j].X1 && planes[i].Y1 <= planes[j].Y2 && planes[i].Y2 >= planes[j].Y1 ) ) ) { planes.Add(MirrorPlane.join(planes[i], planes[j])); planes.RemoveAt(j); planes.RemoveAt(i); unjoinable = false; break; } } if (!unjoinable) { break; } } } } }