Beispiel #1
0
        private void nextUnit()
        {
            unit = unitQueue.FirstOrDefault();
            if (unit == null)
            {
                updateTimer.Stop();
                MessageBox.Show("Out of pieces; technically, you won!");

                return;
            }
            unitQueue = unitQueue.Skip(1);

            unit = DataPart.unit_start(unit, field);

            var bm = DataPart.best_move(unit, field);

            aiMoves = bm.Select(pair => pair.Item2);

            //MessageBox.Show(DataPart.string_from_units(bm.Select(pair => pair.Item1)));

            genUnitCells();
        }
Beispiel #2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (unit == null)
            {
                return;
            }

            DataPart.Unit unit_ = null;
            if (e.KeyCode == Keys.D && !e.Control)
            {
                unit_ = DataPart.apply_move_zipped(DataPart.Move.NewMShift(DataPart.ShiftDirection.E), unit);
            }
            else if (e.KeyCode == Keys.A && !e.Control)
            {
                unit_ = DataPart.apply_move_zipped(DataPart.Move.NewMShift(DataPart.ShiftDirection.W), unit);
            }
            else if (e.KeyCode == Keys.D && e.Control || e.KeyCode == Keys.C)
            {
                unit_ = DataPart.apply_move_zipped(DataPart.Move.NewMShift(DataPart.ShiftDirection.SE), unit);
            }
            else if (e.KeyCode == Keys.A && e.Control || e.KeyCode == Keys.Z)
            {
                unit_ = DataPart.apply_move_zipped(DataPart.Move.NewMShift(DataPart.ShiftDirection.SW), unit);
            }
            else if (e.KeyCode == Keys.Q)
            {
                unit_ = DataPart.apply_move_zipped(DataPart.Move.NewMRotate(DataPart.RotateDirection.CCW), unit);
            }
            else if (e.KeyCode == Keys.E)
            {
                unit_ = DataPart.apply_move_zipped(DataPart.Move.NewMRotate(DataPart.RotateDirection.CW), unit);
            }
            else if (e.KeyCode == Keys.Space)
            {
                unit_   = aiMoves.First();
                aiMoves = aiMoves.Skip(1);
            }
            else if (e.KeyCode == Keys.Enter)
            {
                updateTimer.Interval = 5;
                updateTimer.Enabled  = true;
                updateTimer.Start();
                return;
            }
            else
            {
                return;
            }

            if (DataPart.valid_zipped(field, unit_))
            {
                unit = unit_;
            }
            else
            {
                handleLock();
            }

            if (aiMoves.FirstOrDefault() == null)
            {
                //aiMoves = aiMoves.Skip(1);
                handleLock();
            }


            genUnitCells();
            pictureBox1.Refresh();
        }