/// <summary> /// Can't use cascade delete on database foreign key due to circular dependencies /// </summary> /// <param name="db"></param> internal void CascadeDeleteShoots(RegisterKeeperDb db) { foreach (var shoot in Shoots.ToList()) { db.Shoots.Remove(shoot); } }
// Start is called before the first frame update void Start() { cur = FindObjectOfType <Cursor>(); shot = FindObjectOfType <Shoots>(); navAgent = GetComponent <NavMeshAgent>(); navAgent.updateRotation = false; }
public void MakeCentroid() { Shoots members = new Shoots(); members.AddRange(allShoots); int clsLen = members.Count / clusters.Length; //エルボー法評価のため double distSumAllShoots = 0; string distSumAllShootsOutput = "distSumAllShoots.csv"; foreach (Cluster c in clusters) { c.centroid.DBAacc = (Vec3[])members[0].acc.Clone(); c.members.Add(members[0]); for (int i = 1; i < clsLen; ++i) { double minDist = double.MaxValue; Shoot minS = null; foreach (Shoot s in members) { DBA.CostPath cp; cp = DBA.DpMatching(s.acc, c.centroid.DBAacc); //to callback in DBA-DBA distance //myDBShoots.Add(new DBAShoot()); //最終コストが距離 double dist = cp.cost[cp.cost.Length - 1][cp.cost[cp.cost.Length - 1].Length - 1]; s.distFromCentroid = dist; //エルボー法評価のため全ての距離の和を求める distSumAllShoots += dist; if (dist < minDist) { minDist = dist; minS = s; } } members.Remove(minS); c.members.Add(minS); } } File.WriteAllText(distSumAllShootsOutput, distSumAllShoots.ToString()); }
public Cluster(Cluster c) { members = new Shoots(); prevMembers = new Shoots(); centroid = new DBAShoot(); foreach (Shoot s in c.members) { members.Add(s); } centroid.DBAacc = new Vec3[c.centroid.DBAacc.Length]; for (int i = 0; i < c.centroid.DBAacc.Length; ++i) { centroid.DBAacc[i] = c.centroid.DBAacc[i].Clone(); } }
public void EndAll() { Bg.Dispose(); gold.Dispose(); EncWumpus.Dispose(); EncPit.Dispose(); EnterRoom.Dispose(); LeaveRoom.Dispose(); Trivia.Dispose(); ArrowShot.Dispose(); Shoots.Dispose(); highscore.Dispose(); Menu.Dispose(); bats.Dispose(); Attack.Dispose(); }
public void Kmean(Shoots s, int knumber, int numberOfDbaUpdatesIn) { numberOfDbaUpdates = numberOfDbaUpdatesIn; allShoots = s; clusters = Enumerable.Range(0, knumber).Select(i => new Cluster()).ToArray(); MakeCentroid(); //update : TURE クラスタが更新されなかった場合 //myDBShoots = new DBAShoots(); clusteringFinished = false; while (!clusteringFinished) { Update(); } CalcFinalDistance(); MessageBox.Show("clustering finished"); }
public virtual void RemoveShoot(Shoot shoot) { Shoots.Remove(shoot); }
public virtual void AddShoot(Shoot shoot) { Shoots.Add(shoot); }
//Shoots で直接渡してしまう //DBA(平均の波形)をとる public static DBAShoot CalcAverage(Shoots shoots, int numberOfUpdates) { //仮の平均を決める //最初の平均は1番目の時系列データe //仮の平均 DBAcentroid[n][lengthOfCentroid][axis] //時系列データ seq[t][axis] //centroidを何回計算するか: numberOfUpdates //後のKmeans呼び出しのため、ここで格納 Cluster cluster = new Cluster(); //最初のcentroidはshootnumber1番目の時系列データを代入 // 時系列データの長さが十分にあるとき DBAShoot dba = new DBAShoot(); dba.DBAacc = (Vec3[])shoots[0].acc.Clone(); dba.DBAtime = (double[])shoots[0].time.Clone(); List <Vec3>[] assocTab = Enumerable.Range(0, dba.DBAacc.Length).Select(i => new List <Vec3>()).ToArray(); //時間格納用 List <double>[] assocTabTime = Enumerable.Range(0, dba.DBAacc.Length).Select(i => new List <double>()).ToArray(); for (int nu = 0; nu < numberOfUpdates; nu++) { string output = "centroidNum,DataNum,assocTab[i]x,y,z,assocTabTime[i],\r\n"; //仮の平均と時系列データとの距離を求める foreach (Shoot s in shoots) { string file = "assoctab_" + nu + "_" + s.shootnumber + ".csv"; CostPath table = DpMatching(dba.DBAacc, s.acc); int i = table.cost.Length - 1; //時系列データにおけるcentroidの数(固定) int j = table.cost[0].Length - 1; //比較する時系列データの数(固定)(X,Y,Zともに共通) while (i > 0 && j > 0) { //時系列データを対応付け //assocTab[xyz][i] = 関連付けた仮の平均に対する時系列データ assocTab[i].Add(s.acc[j]); assocTabTime[i].Add(s.time[j]); output += i + ", " + j + "," + s.acc[j].x + ", " + s.acc[j].y + ", " + s.acc[j].z + ", " + s.time[j] + "\r\n"; if (table.path[i][j] == 0) { //斜め i--; j--; } else if (table.path[i][j] == 1) { //たて j--; } else if (table.path[i][j] == 2) { //よこ i--; } } File.WriteAllText(file, output); } } int n = 0; foreach (List <Vec3> assoc in assocTab) { Vec3 asum = new Vec3(); // + / はCluster.csでoperaterとして定義済み foreach (Vec3 a in assoc) { asum += a; } if (assoc.Count > 0) { asum /= assoc.Count; //DBAの値 nはカウントのみ dba.DBAacc[n] = asum; //個別データとDBAcentroidとのコストの差を表示したい //[対応するcentroidの数][何番目のデータ]:単位時間あたりのコストの増減 //dba.DBAtime[n] = assocTabTime[assoc.Count][n]; //DBAの時刻は該当するデータの時間の平均 } else if (n > 0) { //比較 長さが不均等なときは直前の値を適用 dba.DBAacc[n] = dba.DBAacc[n - 1]; } n++; } int m = 0; foreach (List <double> assoc in assocTabTime) { //DBAtime* 平均の時間を入れたい場合は以下 //double tsum = 0; //foreach (double t in assoc) //{ // tsum = tsum + t; //} if (assoc.Count > 0) { //DBAの時刻は該当するデータの時間の平均にしたい場合 //tsum = tsum / assoc.Count; //dba.DBAtime[m] = tsum; //下記 インデックスエラーを避けるため //if (m < assoc.Count) //{ dba.DBAtime[m] = m; //} } //else if (m > 0) //{ // //比較 長さが不均等なときは直前の値を適用 // dba.DBAtime[m] = assoc[m - 1]; //} m++; } return(dba); }
public void Play(Shoots shoot) { System.Console.WriteLine(this.PlayerName); shoot.Shoot(); }
public double distFromCentroid; //クラスタの中心からの距離 クラスタークラスタ間用 public Cluster() { members = new Shoots(); prevMembers = new Shoots(); centroid = new DBAShoot(); }
private void timer2_Tick(object sender, EventArgs e) { // create New Shoot in game every sec // Create Game Shoot Random rnd = new Random(); int pos1, pos2, pos3; List <int> L = new List <int>(); L.Add(prev1); L.Add(prev2); L.Add(prev3); L.Sort(); while (true) { pos1 = rnd.Next(0, 8); pos2 = rnd.Next(0, 8); pos3 = rnd.Next(0, 8); List <int> L1 = new List <int>(); L1.Add(pos1); L1.Add(pos2); L1.Add(pos3); if (pos1 != pos2 && pos2 != pos3 && pos1 != pos3) { bool ok = true; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (L[i] == L1[j]) { ok = false; } } } if (ok) { break; } } } prev1 = pos1; prev2 = pos2; prev3 = pos3; PictureBox picture = new PictureBox { Name = "pictureBox", Size = shootgame.Size, BackColor = shootgame.BackColor, Location = new Point(posofshoots[pos1], 58), // BackColor = System.Drawing.Color.Lime, Image = shootgame.Image, SizeMode = shootgame.SizeMode, }; this.Controls.Add(picture); Shoots.Add(picture); int r1 = rnd.Next(1, 4); // 1 for horz , 2 for left ,3 for right // lvl 2 of game if (lvl2 == true) { moveLeft.Add(r1); } else { moveLeft.Add(1); } if (lvl2) { PictureBox picture1 = new PictureBox { Name = "pictureBox", Size = shootgame2.Size, BackColor = shootgame2.BackColor, Location = new Point(posofshoots[pos2], 58), // BackColor = System.Drawing.Color.Lime, Image = shootgame2.Image, SizeMode = shootgame2.SizeMode, }; this.Controls.Add(picture1); Shoots.Add(picture1); r1 = rnd.Next(1, 4); // 1 for horz , 2 for left ,3 for right // lvl 2 of game if (lvl2 == true) { moveLeft.Add(r1); } else { moveLeft.Add(1); } PictureBox picture2 = new PictureBox { Name = "pictureBox", Size = shootgame3.Size, BackColor = shootgame3.BackColor, Location = new Point(posofshoots[pos3], 58), // BackColor = System.Drawing.Color.Lime, Image = shootgame3.Image, SizeMode = shootgame3.SizeMode, }; this.Controls.Add(picture2); Shoots.Add(picture2); r1 = rnd.Next(1, 4); // 1 for horz , 2 for left ,3 for right // lvl 2 of game if (lvl2 == true) { moveLeft.Add(r1); } else { moveLeft.Add(1); } } // determine objects that not in form and delete it if (Shoots.Count > 0) { timer2.Enabled = false; for (int i = 0; i < Shoots.Count; i++) { if (Shoots[i].Top > 640) // not in form { Shoots[i].Dispose(); Shoots.RemoveAt(i); i = -1; if (Health.Value > 0) { Health.Value -= 25; } } } timer2.Enabled = true; } if (PlayerShoots.Count > 20) { timer2.Enabled = false; for (int i = 0; i < PlayerShoots.Count; i++) { if (PlayerShoots[i].Top < 23) { PlayerShoots[i].Dispose(); PlayerShoots.RemoveAt(i); i = -1; // to start loop from first after remove // MessageBox.Show(i.ToString()); } } timer2.Enabled = true; } }
private void timer1_Tick(object sender, EventArgs e) { Scoretxt.Text = "Score : " + score.ToString(); if (score == 500) { distmov = 2; } if (score == 1000) { distmov = 3; } if (score == 1500) { distmov = 4; } if (score == 2000) { distmov = 5; } if (score == 100 && lvl2 == false) { lvl2 = true; Point p = new Point(); p.X = 278; p.Y = 331; if (music) { playerwinsound.Play(); } lvltwo.Location = p; lvltwo.Visible = true; timer1.Enabled = false; timer2.Enabled = false; } if (playwithkeyboard) { if (keyleft) { if (player.Left - 10 > 2) { player.Left -= 10; } // keyleft = false; } else if (keyright) { if (player.Left + 10 < 709) { player.Left += 10; } // keyright = false; } else if (keyup) { if (player.Top - 10 > 2) { player.Top -= 10; } //keyup = false; } else if (keydown) { if (player.Top + 10 < 540) { player.Top += 10; } //keydown = false; } } else { if (inside && Cursor.Position.X - (player.Width + 10) * 2 > 2 && Cursor.Position.X - (player.Width + 10) * 2 < 709) { player.Left = Cursor.Position.X - (player.Width + 10) * 2; } //if (Cursor.Position.X - Left - (player.Width / 2) >= 2 && Cursor.Position.X - Left - (player.Width / 2) < 709) //{ // if (Cursor.Position.Y - Top - 31 - (player.Height / 2) > 2 && Cursor.Position.Y - Top - 31 - (player.Height / 2) <540) // player.Location = new Point(Cursor.Position.X - Left - (player.Width / 2), Cursor.Position.Y - Top - 31 - (player.Height / 2)); //} } // move Shoots for (int i = 0; i < Shoots.Count; i++) { Shoots[i].Top += distmov; if (lvl2) // move diagonal in lvl2 { if (moveLeft[i] == 2) // move left { Shoots[i].Left -= distmov; if (Shoots[i].Left <= -20) { moveLeft[i] = 3; // move right } } else if (moveLeft[i] == 3) // move right { Shoots[i].Left += 1; if (Shoots[i].Left >= 768) { moveLeft[i] = 2; // move left } } } } for (int i = 0; i < PlayerShoots.Count; i++) { PlayerShoots[i].Top -= 5; } // Create New Shoot if (keyspace || movdown) { // playershootsound.Play(); Point p = new Point(); p = player.Location; PictureBox picture = new PictureBox { Name = "pictureBox", Size = shootplayer.Size, BackColor = shootplayer.BackColor, Location = new Point(p.X + 45, p.Y), // BackColor = System.Drawing.Color.Lime, Image = shootplayer.Image, SizeMode = shootplayer.SizeMode, }; keyspace = false; movdown = false; this.Controls.Add(picture); PlayerShoots.Add(picture); } // Remove Shoots that hit for (int i = 0; i < PlayerShoots.Count; i++) { for (int j = 0; j < Shoots.Count; j++) { if (Shoots[j].Bounds.IntersectsWith(PlayerShoots[i].Bounds)) { score += 10; PlayerShoots[i].Visible = false; Shoots[j].Visible = false; this.Controls.Remove(Shoots[j]); this.Controls.Remove(PlayerShoots[i]); Shoots[j].Dispose(); PlayerShoots[i].Dispose(); PlayerShoots.RemoveAt(i); Shoots.RemoveAt(j); moveLeft.RemoveAt(j); break; } } } for (int j = 0; j < Shoots.Count; j++) { if (Shoots[j].Bounds.IntersectsWith(player.Bounds)) { Shoots[j].Visible = false; this.Controls.Remove(Shoots[j]); Shoots[j].Dispose(); Shoots.RemoveAt(j); moveLeft.RemoveAt(j); if (Health.Value > 0) { Health.Value -= 25; } if (Health.Value == 0) { if (music) { gameover.Play(); } timer1.Enabled = false; timer2.Enabled = false; Point p = new Point(); p.X = 278; p.Y = 331; gameover1.Location = p; gameover1.Visible = true; } break; } } if (timer1.Enabled && Health.Value == 0) { if (music) { gameover.Play(); } timer1.Enabled = false; timer2.Enabled = false; Point p = new Point(); p.X = 278; p.Y = 331; gameover1.Location = p; gameover1.Visible = true; } }