コード例 #1
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        private void button10_Click(object sender, EventArgs e)
        {
            Queue <park> Q = new Queue <park>();

            Q.Enqueue(p1);

            label1.Text = "Working ..."; Application.DoEvents();

            searchResults r = parkSpaceLogic.SpaceSearch2(Q);

            int sol_count = r.solutions.Count;

            int steps_to_sol = -1;

            if (sol_count > 0)
            {
                r = parkSpaceLogic.SpaceSearch2(r.solutions);

                p1 = r.lastNode;

                steps_to_sol = r.distance_counter - 1;

                pictureBox1.Refresh();
            }

            label1.Text = r.states.ToString() + " states, " + sol_count.ToString() + " solution(s), steps to solution: " + steps_to_sol.ToString();;
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            park park = db.Seikluspark.Find(id);

            db.Seikluspark.Remove(park);
            db.SaveChanges();
            return(RedirectToAction("Kohal"));
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        public Form1()
        {
            InitializeComponent();

            this.button1_Click(this, null);

            p1 = new park("{6x6:12-0-2,34-0-2,21-1-2,4-1-3,1-0-3,6-0-3,9-1-2,14-1-2,11-1-2,24-1-2,28-0-2,22-0-2}");
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        private void button8_Click(object sender, EventArgs e)
        {
            label1.Text = "Solving ...";

            Queue <park> Q = new Queue <park>();

            Q.Enqueue(p1);

            searchResults r = parkSpaceLogic.SpaceSearch2(Q);

            if (r.solutions.Count == 0)
            {
                MessageBox.Show("No solutions found!", "Error");

                return;
            }

            searchResults r2 = parkSpaceLogic.SpaceSearch2(r.solutions);

            int current_steps_to_sol = r2.D[p1.GetHashCode()];

            int moveCount = 0;

            while (current_steps_to_sol > 0)
            {
                moveCount++;

                movesList L = parkLogic.generateMoves2(p1);

                for (int i = 0; i < L.count; i++)
                {
                    park p2 = p1.Clone();

                    p2 = parkLogic.makeMove2(p2, L.car_ind[i], L.dir[i]);

                    int steps_to_sol = r2.D[p2.GetHashCode()];

                    if (steps_to_sol < current_steps_to_sol)
                    {
                        current_steps_to_sol = steps_to_sol;

                        p1 = parkLogic.makeMove2(p1, L.car_ind[i], L.dir[i]);

                        pictureBox1.Refresh();

                        Application.DoEvents();

                        System.Threading.Thread.Sleep(250);

                        break;
                    }
                }
            }

            label1.Text = "Done1";
        }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "Id,inimesed,käepaelad")] park park)
 {
     if (ModelState.IsValid)
     {
         db.Entry(park).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Kohal"));
     }
     return(View(park));
 }
コード例 #6
0
        public ActionResult Create([Bind(Include = "Id,inimesed,käepaelad")] park park)
        {
            if (ModelState.IsValid)
            {
                db.Seikluspark.Add(park);
                db.SaveChanges();
                return(RedirectToAction("ülevaade"));
            }

            return(View(park));
        }
コード例 #7
0
        // GET: Seikluspark/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            park park = db.Seikluspark.Find(id);

            if (park == null)
            {
                return(HttpNotFound());
            }
            return(View(park));
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        private void button1_Click(object sender, EventArgs e)
        {
            PUZZLE_WIDTH = (int)numericUpDown1.Value;

            PUZZLE_HEIGHT = (int)numericUpDown2.Value;

            CARS = (int)numericUpDown3.Value;

            p1 = parkLogic.generatePark(PUZZLE_WIDTH, PUZZLE_HEIGHT, CARS);

            selected_car = 0;

            generateColorTab();

            updateInterface();
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        public string printPark(park p)
        {
            string res = "";

            for (int i = 0; i < p.occupancy.Length; i++)
            {
                res += p.occupancy[i].ToString() + " ";

                if (i % p.width == p.width - 1)
                {
                    res += Environment.NewLine;
                }
            }

            return(res);
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                p1 = new park(Clipboard.GetText());

                PUZZLE_WIDTH = p1.width;

                PUZZLE_HEIGHT = p1.height;

                CARS = p1.count;

                generateColorTab();

                updateInterface();
            }
            catch (Exception)
            {
                MessageBox.Show("Data in clipboard does not represent a valid state!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            int xblock = e.X / bw;

            int yblock = e.Y / bw;

            int block = yblock * p1.width + xblock;

            int car = p1.occupancy[block];

            if (car != 0)
            {
                selected_car = car;
            }
            else
            {
                if (selected_car != 0)
                {
                    int i = selected_car - 1;

                    if (p1.alignment[i] == 0)
                    {
                        if (block >= p1.pos[i] + p1.length[i])
                        {
                            int dir = block - p1.pos[i] - p1.length[i] + 1;

                            if (parkLogic.checkMove(p1, i, dir))
                            {
                                p1 = parkLogic.makeMove2(p1, i, dir);
                            }
                        }

                        if (block < p1.pos[i])
                        {
                            int dir = block - p1.pos[i];
                            if (parkLogic.checkMove(p1, i, dir))
                            {
                                p1 = parkLogic.makeMove2(p1, i, dir);
                            }
                        }
                    }
                    else
                    {
                        //if (block == p1.pos[i] + p1.length[i]*p1.width)
                        if (block > p1.pos[i])
                        {
                            double dir_db = ((double)(block - p1.pos[i]) / p1.width) - p1.length[i] + 1;

                            if (dir_db % 1 == 0)
                            {
                                int dir = Convert.ToInt32(dir_db);

                                if (parkLogic.checkMove(p1, i, dir))
                                {
                                    p1 = parkLogic.makeMove2(p1, i, dir);
                                }
                            }
                        }

                        //if (block == p1.pos[i] - p1.width)
                        if (block < p1.pos[i])
                        {
                            double dir_db = ((double)(block - p1.pos[i]) / p1.width);

                            if (dir_db % 1 == 0)
                            {
                                int dir = Convert.ToInt32(dir_db);

                                if (parkLogic.checkMove(p1, i, dir))
                                {
                                    p1 = parkLogic.makeMove2(p1, i, dir);
                                }
                            }
                        }
                    }

                    selected_car = 0;
                }
            }

            // textBox1.Text = p1.getString();

            pictureBox1.Refresh();
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: oranke/rushhour
        private void button3_Click(object sender, EventArgs e)
        {
            MIN_SOLS = (int)numericUpDown4.Value;

            int trials = 0;

            int max_sol_steps = 0;

            //string sols_vector = "";

            park p = new park();

            park best_park = new park();

            button3.Enabled = false;

            button2.Enabled = true;

            Application.DoEvents();

            DateTime st = DateTime.Now;

            while (!ABORT_FLAG)
            //for (int i=0; i<1000; i++)
            {
                p = parkLogic.generatePark(PUZZLE_WIDTH, PUZZLE_HEIGHT, CARS);

                trials++;

                label1.Text = "Searching ... (tried " + trials.ToString() + " configuations, max solution steps = " + max_sol_steps.ToString() + ")";

                this.Refresh();

                Application.DoEvents();

                if (p.count < CARS)
                {
                    continue;
                }

                Queue <park> Q = new Queue <park>();

                Q.Enqueue(p);

                searchResults r = parkSpaceLogic.SpaceSearch2(Q);

                if (r.states < 1)
                {
                    continue;
                }

                if (r.solutions.Count == 0)
                {
                    continue;
                }

                r = parkSpaceLogic.SpaceSearch2(r.solutions);

                p = r.lastNode;

                int steps_to_sol = r.distance_counter - 1;



                if (steps_to_sol > max_sol_steps)
                {
                    best_park = p;

                    max_sol_steps = steps_to_sol;
                }

                if (steps_to_sol >= MIN_SOLS)
                {
                    StreamWriter res_file = File.AppendText(Directory.GetCurrentDirectory() + "\\car_park_puzzles.txt");

                    res_file.WriteLine(steps_to_sol.ToString("00 solutions: ") + p.ToString());

                    res_file.Flush();

                    res_file.Close();
                }
            }

            // this.Text  = DateTime.Now.Subtract(st).TotalSeconds.ToString();

            p1 = best_park;

            generateColorTab();

            updateInterface();

            button4_Click(null, null);

            button3.Enabled = true;

            button2.Enabled = false;

            ABORT_FLAG = false;

            //Clipboard.SetText(sols_vector);
        }