コード例 #1
0
ファイル: MapState.cs プロジェクト: virtuoushub/game-off-2016
    public MapState Apply(ApplicableOperator op)
    {
        this.applicableConnections.Remove(op);
        RoomDoor roomDoor  = op.sourceRoomDoor;
        RoomDoor otherRoom = op.connectionRoomDoor;

        openDoors.Remove(roomDoor);
        lastDoor = roomDoor;
        otherRoom.room.roomId = rooms.Count;
        MapState newState = new MapState();

        foreach (Room room in rooms)
        {
            if (room.roomId == roomDoor.room.roomId)
            {
                Room clonedRoom = roomDoor.room.clone();
                Door clonedDoor = clonedRoom.GetDoor(roomDoor.door.doorId);
                Room.ConnectDoors(clonedRoom, clonedDoor, otherRoom.room, otherRoom.door);
                newState.AddRoom(clonedRoom);
            }
            else
            {
                newState.AddRoom(room.clone());
            }
        }
        newState.AddRoom(otherRoom.room);
        return(newState);
    }
コード例 #2
0
    void step()
    {
//		Debug.Log ("Step forward");
//		Debug.Log ("Actual state: " + actualState);
        counter++;
        if (counter == 10)
        {
            throw new Exception("StackOverflow");
        }
        ApplicableOperator chosenOperator = actualState.getRandomOperator();

        if (chosenOperator == null)
        {
            stepBack();
        }
        else
        {
//		Debug.Log ("Searching connection for [Room: " + randomOpenDoor.room.roomId + ", Door: (" + randomOpenDoor.door.doorId + ") " + randomOpenDoor.door.position + "]");
            actualState = actualState.Apply(chosenOperator);
            mapStates.Add(actualState);

            if (IsWinningState())
            {
                winningState = actualState;
                return;
            }
            GenerateApplicableOperators();
        }
        step();
    }