public IActionResult MazeStep(string drc) { if (!_levelProcessRepository.CheckAuthority(Request.Cookies["token"], 10) || (drc != "n" && drc != "s" && drc != "w" && drc != "e")) { return(new JsonResult(new { status = "Fail" })); } Maze.Direction direction = Maze.Direction.Unknown; switch (drc) { case "n": direction = Maze.Direction.UP; break; case "s": direction = Maze.Direction.DOWN; break; case "w": direction = Maze.Direction.LEFT; break; case "e": direction = Maze.Direction.RIGHT; break; } Maze.Edges edges = (Maze.Edges)_mazeProcessRepository.GetCurState(Request.Cookies["token"]).walls; if (direction.HasFlag(Maze.Direction.Unknown) || edges.HasFlag((Maze.Edges)(int) direction)) { return(new JsonResult(new { status = "Fail" })); } int newedges = _mazeProcessRepository.Step(Request.Cookies["token"], direction); return(new JsonResult(new { status = "Success", newedges })); }
public int Step(string token, Maze.Direction direction) { var pro = _context.MazeProcesses.FirstOrDefault(p => string.Equals(p.Token, token)); if (pro == null) { return(Maze.Map[0][0]); } else { Maze.Edges edges = (Maze.Edges)Maze.Map[pro.x][pro.y]; switch (direction) { case Maze.Direction.UP: if (!edges.HasFlag(Maze.Edges.UP)) { pro.y = pro.y + 1; } break; case Maze.Direction.DOWN: if (!edges.HasFlag(Maze.Edges.DOWN)) { pro.y = pro.y - 1; } break; case Maze.Direction.LEFT: if (!edges.HasFlag(Maze.Edges.LEFT)) { pro.x = pro.x - 1; } break; case Maze.Direction.RIGHT: if (!edges.HasFlag(Maze.Edges.RIGHT)) { pro.x = pro.x + 1; } break; default: break; } _context.SaveChanges(); return(Maze.Map[pro.x][pro.y]); } }
private void VisitRec(int col, int row) { // mark visited Visited [col, row] = true; // list of possible destinations List <Maze.Direction> pending = new List <Maze.Direction> (FourRoses); // while possible destinations while (pending.Count > 0) { // extract one from the list int index = RndFactory.Next() % pending.Count; Maze.Direction direction = pending[index]; pending.RemoveAt(index); // relative to this cell int c = col, r = row; // calculate the next one switch (direction) { case Maze.Direction.N: r--; break; case Maze.Direction.E: c++; break; case Maze.Direction.S: r++; break; case Maze.Direction.W: c--; break; } // if destination is valid if (CellIsValid(c, r) && !Visited [c, r]) { // open the wall and explore recursively Maze.UnsetWall(col, row, direction); VisitRec(c, r); } } }
public static Vector2Int ToVec(this Maze.Direction direction) { switch (direction) { case Maze.Direction.Right: return(new Vector2Int(1, 0)); case Maze.Direction.Left: return(new Vector2Int(-1, 0)); case Maze.Direction.Down: return(new Vector2Int(0, 1)); case Maze.Direction.Up: return(new Vector2Int(0, -1)); } return(Vector2Int.zero); }
/// <summary> /// エージェントを1回行動させる /// </summary> private void ActAgent() { var locate = new Maze.CellLocate(Agent.CurrentLocate); MazeCellViews[locate.X, locate.Y].CellCssClass = CSS_CLASS_PATH; double qValue = Agent.Act(); MazeCellViews[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].CellCssClass = "bg-success"; if (qValue > 0) { Maze.Direction direction = Agent.GetMaxQDirection(locate); EnvMaze.Cells[locate.X, locate.Y].Text = DirectionSet[direction]; if (!EnvMaze.Cells[locate.X, locate.Y].IsStart) { MazeCellViews[locate.X, locate.Y].Text = DirectionSet[direction]; } } }
protected override void performMove(Keys direction) { switch (direction) { case Keys.W: maze.move(currentDirection); break; case Keys.A: currentDirection = (Maze.Direction)(((int)currentDirection + 3) % 4); break; case Keys.S: currentDirection = (Maze.Direction)(((int)currentDirection + 2) % 4); break; case Keys.D: currentDirection = (Maze.Direction)(((int)currentDirection + 1) % 4); break; } }
public void Move(Maze.Direction direction) { player.Move(direction, Quaternion.identity); }
protected override void performMove(Keys direction) { switch (direction) { case Keys.W: maze.move(currentDirection); break; case Keys.A: currentDirection = (Maze.Direction) (((int) currentDirection + 3)%4); break; case Keys.S: currentDirection = (Maze.Direction) (((int) currentDirection + 2)%4); break; case Keys.D: currentDirection = (Maze.Direction) (((int) currentDirection + 1)%4); break; } }
public void Mutate() { direction = (Maze.Direction)Parameters.randomGenerator.Next(4); // refaire un tirage au sort pour une nouvelle direction (4 directions). }
public MazeGene(MazeGene g) { direction = g.direction; // Constructeur pour copier un gène donné en paramètre. }
public MazeGene() { direction = (Maze.Direction)Parameters.randomGenerator.Next(4); // Constructeur pour créer un gène aléatoirement. }
public void Move(Maze.Direction direction, Quaternion rot) { //回転中は入力を受け付けない if (isRotate) { return; } var currentPoint = transform.localPosition; var nextPoint = Vector3.zero; var rotatePoint = Vector3.zero; var rotateAxis = Vector3.zero; switch (direction) { case Maze.Direction.Right: { nextPoint = currentPoint + rot * new Vector3(cubeSize, 0f, 0f); rotatePoint = currentPoint + rot * new Vector3(cubeSizeHalf, -cubeSizeHalf, 0f); rotateAxis = rot * new Vector3(0, 0, -1); } break; case Maze.Direction.Left: { nextPoint = currentPoint + rot * new Vector3(-cubeSize, 0f, 0f); rotatePoint = currentPoint + rot * new Vector3(-cubeSizeHalf, -cubeSizeHalf, 0f); rotateAxis = rot * new Vector3(0, 0, 1); } break; case Maze.Direction.Down: { nextPoint = currentPoint + rot * new Vector3(0f, 0f, -cubeSize); rotatePoint = currentPoint + rot * new Vector3(0f, -cubeSizeHalf, -cubeSizeHalf); rotateAxis = rot * new Vector3(-1, 0, 0); } break; case Maze.Direction.Up: { nextPoint = currentPoint + rot * new Vector3(0f, 0f, cubeSize); rotatePoint = currentPoint + rot * new Vector3(0f, -cubeSizeHalf, cubeSizeHalf); rotateAxis = rot * new Vector3(1, 0, 0); } break; } // 入力がない時はコルーチンを呼び出さないようにする if (rotatePoint == Vector3.zero) { return; } var nextRotation = Quaternion.AngleAxis(90, rotateAxis) * transform.localRotation; var nextPos = nextPoint.ToMazePos(); // いけるかどうか var floor = FloorBehaviour.GetInstance(); var tile = floor.Get(nextPos); if (tile == null || tile.tileId != GetSideId(nextRotation)) { //var currentPoint = currentPoint; //var currentPos = currentPoint.ToMazePos(); //Debug.LogFormat("Cannot Move\n Current(pos={0}, id={1}, rot={2})\n Next(pos={3}, id={4}, rot={5})\n CurrentTile(pos={6}, id={7})\n NextTile(pos={8}, id={9})", // currentPoint, GetSideId(transform.localRotation), transform.localRotation.eulerAngles, // nextPoint, GetSideId(nextRotation), nextRotation.eulerAngles, // currentPos, FloorBehaviour.GetInstance().Get(currentPos.x, currentPos.y).tileId, // nextPos, tile.tileId); { var pos1 = GetCurrentPos().ToCellPos(); var pos2 = nextPos.ToCellPos(); var mazepos = new Maze.Cell() { X = (pos1.X + pos2.X) / 2, Y = (pos1.Y + pos2.Y) / 2 }.ToVecMazePos(); var map = floor.maze.GetMaze(); if (0 <= mazepos.y && mazepos.y < map.GetLength(1) && 0 <= mazepos.x && mazepos.x < map.GetLength(0)) { if (map[mazepos.x, mazepos.y] == Maze.Wall) { floor.CreateWall(GetCurrentPos(), nextPos); } } } var modelRenderer = transform.Find("CubeModel").Find("Model").GetComponent <Renderer>(); var tileId = CubeBehaviour.GetSideId(CubeBehaviour.GetMoveRotation(direction, transform.localRotation)); StartCoroutine(UnableMove(rotatePoint, rotateAxis, new ChangeColor[] { (Color diffuse, Color emission) => { if (tile != null) { tile.material.color = diffuse; tile.material.SetColor("_EmissionColor", emission); } }, (Color diffuse, Color emission) => { modelRenderer.materials[tileId].color = diffuse; modelRenderer.materials[tileId].SetColor("_EmissionColor", emission); }, }, () => { })); GameStats.currentStats.miss++; Camera.main.GetComponent <AudioSource>().PlayOneShot(audioMiss); } else { var goal = floor.goal; var coins = floor.coins; StartCoroutine(MoveCube(rotatePoint, rotateAxis, () => { coins.ForEach(e => { if (e.pos == nextPos) { Camera.main.GetComponent <AudioSource>().PlayOneShot(audioCoin); Destroy(e.obj); GameStats.currentStats.coin++; } }); coins.RemoveAll(e => e.pos == nextPos); if (nextPos == goal) { if (TimeAttack.currentState != null) { onGoalInTimeAttack.Invoke(); } else { onGoal.Invoke(); } } })); } }