예제 #1
0
파일: Program.cs 프로젝트: opot/BrainTic
        /// <summary>
        /// In this constructor main cycle is performed
        /// </summary>
        /// <param name="fold">path to game folder</param>
        /// <param name="player">player symbol</param>
        /// <param name="time">permited time</param>
        public Program(string fold, CellState player, int time)
        {
            start = DateTime.Now;

            Field field = new Field(fold);
            int delta = 0;
            # if DEBUG
            delta = (new Random()).Next(Field.SIZE);//col shift, makes game more different
            #endif
            Solution root = new Solution(field, Solution.invertCell(player));
            for (int i = 0; i < Field.SIZE; i++) {
                Solution buf = new Solution(root, (i + delta) % Field.SIZE);
                branch[i] = buf;
                if (!buf.isFinalized)
                    que.Enqueue(buf);
            }

            while ((DateTime.Now - start).TotalMilliseconds + 300 < time && que.Count != 0)//main cycle
                Solve(que.Dequeue());

            Solution max = branch[0];

            for (int i = 1; i < Field.SIZE; i++)
                if (branch[i] != null)
                    max = branch[i].isGreater(max);

            int turn = Directory.GetFiles(fold).Length / 2 + 1;
            string path = fold + (player == CellState.Cross ? "X" : "O") + turn.ToString() + ".txt";
            File.WriteAllLines(path, new String[] { max.getTurn() });
        }
예제 #2
0
파일: Field.cs 프로젝트: opot/BrainTic
        /// <summary>
        /// Constructor that copies specified field and make move to specified column
        /// </summary>
        /// <param name="last">Field to copy</param>
        /// <param name="col">Column to move</param>
        /// <param name="player">Player who moves</param>
        public Field(Field last, int col, CellState player)
        {
            cells = new CellState[SIZE][];
            for (int i = 0; i < SIZE; i++)
                cells[i] = last.cells[i];

            cells[col] = new CellState[SIZE];
            int delta = 0;
            if (col == block1 || col == block2) {
                delta = 1;
                cells[col][SIZE - 1] = CellState.Block;
            }
            cells[col][SIZE - 1 - delta] = player;

            for (int i = 0; i < SIZE - 1 - delta; i++)
                cells[col][i] = last.cells[col][i + 1];
        }