private void button2_Click(object sender, EventArgs e) { int uniqueCombinations = 0; int comb_count = all_combinations.Count; for (int i = 0; i < comb_count; i++) { bool isunique = true; for (int j = i + 1; j < comb_count; j++) { ShipState ss1 = all_combinations[i]; ShipState ss2 = all_combinations[j]; if ( Math.Abs(ss1.xpos - ss2.xpos) < coordEpsilon && Math.Abs(ss1.ypos - ss2.ypos) < coordEpsilon && Math.Abs(ss1.xspeed - ss2.xspeed) < speedEpsilon && Math.Abs(ss1.yspeed - ss2.yspeed) < speedEpsilon && Math.Abs(ss1.angle - ss2.angle) < angleEpsilon ) { isunique = false; break; } } if (isunique) { uniqueCombinations++; } } label14.Text = Convert.ToString(uniqueCombinations); }
public void set(ShipState other) { xpos = other.xpos; ypos = other.ypos; angle = other.angle; xspeed = other.xspeed; yspeed = other.yspeed; }
public static ShipState getFromPool() { if (pool.Count > 0) { ShipState ss = pool.Pop(); ss.clear(); return(ss); } else { ShipState ss = new ShipState(); ss.clear(); return(ss); } }
public static ShipState getFromPool() { if (pool.Count > 0) { ShipState ss = pool.Pop(); ss.clear(); return ss; } else { ShipState ss = new ShipState(); ss.clear(); return ss; } }
private void DrawShipsForTurn(int level, Node <ShipState> parentNode) { if (drawTurn == level + 1) { foreach (Node <ShipState> node in parentNode.childrenNodes) { ShipState ss = node.value; drawGraphics.FillRectangle(drawBrush, (int)(ss.xpos * scale), (int)(ss.ypos * scale), 1, 1); } } else { foreach (Node <ShipState> node in parentNode.childrenNodes) { DrawShipsForTurn(level + 1, node); } } }
private void CalcNextShipState(int turnNumber, ShipState ss) { if (turnNumber == calcTurn) { ShipState putss = ShipState.getFromPool(); putss.set(ss); all_combinations.Add(putss); return; } ShipState newss = ShipState.getFromPool(); for (int thr = 0; thr <= divThrust; thr++) { for (int tur = 0; tur <= divTurn; tur++) { newss.set(ss); newss.move(thr * maxThrust / divThrust, tur * (2 * maxTurn) / divTurn - maxTurn); CalcNextShipState(turnNumber + 1, newss); } } newss.putToPool(); }
private void CalcAllShipStates(int turnNumber, Node <ShipState> parentNode) { allNodesNumber++; for (int thr = 0; thr <= divThrust; thr++) { for (int tur = 0; tur <= divTurn; tur++) { ShipState newss = ShipState.getFromPool(); newss.set(parentNode.value); newss.move(thr * maxThrust / divThrust, tur * (2 * maxTurn) / divTurn - maxTurn); Node <ShipState> newnode = new Node <ShipState>(newss, parentNode); if (turnNumber + 1 == calcTurn) { allNodesNumber++; } else { CalcAllShipStates(turnNumber + 1, newnode); } } } }
private void drawBackBuffer() { if (_backBuffer != null && (_backBuffer.Width != panel1.ClientSize.Width || _backBuffer.Height != panel1.ClientSize.Height) ) { _backBuffer.Dispose(); _backBuffer = null; } if (_backBuffer == null) { _backBuffer = new Bitmap(panel1.ClientSize.Width, panel1.ClientSize.Height); } Graphics gr = Graphics.FromImage(_backBuffer); prepareGraphics(gr); cleanLists(); DateTime startTime = DateTime.Now; rootNode = new Node <ShipState>(ShipState.getFromPool()); allNodesNumber = 0; CalcAllShipStates(0, rootNode); TimeSpan deltaTime = DateTime.Now.Subtract(startTime); //CalcNextShipState(0, ShipState.getFromPool()); //int comb_count = all_combinations.Count; //if(true) //{ // ShipState ssNext = ShipState.getFromPool(); // foreach (ShipState ss in all_combinations) // { // ssNext.set(ss); // ssNext.move(0,0); // gr.DrawLine(Pens.Green, // (int)(ss.xpos * 50), (int)(ss.ypos * 50), // (int)(ssNext.xpos * 50), (int)(ssNext.ypos * 50)); // } // ssNext.putToPool(); //} //foreach (ShipState ss in all_combinations) //{ // gr.FillRectangle(Brushes.White, (int)(ss.xpos * scale), (int)(ss.ypos * scale), 1, 1); //} drawGraphics = gr; for (drawTurn = calcTurn; drawTurn >= 1; drawTurn--) { Color color = Color.FromArgb(50, 50, 50); if (drawTurn - 1 < colors.Count) { color = colors[drawTurn - 1]; } drawBrush = new SolidBrush(color); DrawShipsForTurn(0, rootNode); } gr.Dispose(); label7.Text = Convert.ToString(allNodesNumber); label14.Text = "?"; label9.Text = Convert.ToString((int)deltaTime.TotalMilliseconds); }
private void CalcNextShipState(int turnNumber, ShipState ss) { if (turnNumber == calcTurn) { ShipState putss = ShipState.getFromPool(); putss.set(ss); all_combinations.Add(putss); return; } ShipState newss = ShipState.getFromPool(); for (int thr = 0; thr <= divThrust; thr++) for (int tur = 0; tur <= divTurn; tur++) { newss.set(ss); newss.move(thr * maxThrust / divThrust, tur * (2*maxTurn) / divTurn - maxTurn); CalcNextShipState(turnNumber + 1, newss); } newss.putToPool(); }