Skip to content
Snippets Groups Projects
Commit 75894557 authored by Tessaris Sergio's avatar Tessaris Sergio
Browse files

fix: WumpusWorld.random arg types

parent fab03f3c
No related branches found
No related tags found
No related merge requests found
from dataclasses import dataclass
from enum import Enum
import json
import random
import sys
from typing import Any, Iterable, NamedTuple, Dict, Sequence, Tuple
from typing import Any, Iterable, Dict, Sequence, Tuple, Union
from .gridworld import Actions, Agent, WorldObject, GridWorld, Coordinate, coord, GridWorldException, Percept
......@@ -239,10 +237,10 @@ class Hunter(Agent):
class WumpusWorld(GridWorld):
@classmethod
def classic(cls, size: int = 4, seed=None, pitProb: float = .2):
def classic(cls, size: Union[int, Coordinate] = 4, seed=None, pitProb: float = .2, **kwargs):
"""Create a classic wumpus world problem of the given size. The agent is placed in (0,0) facing north and there's exactly one wumpus and a gold ingot. The seed is used to initialise the random number generation and pits are placed with pitProb probability."""
world = cls(coord(size, size), [])
world = cls(size if isinstance(size, Coordinate) else coord(size, size), [])
agentPos = coord(0, 0)
......@@ -254,13 +252,8 @@ class WumpusWorld(GridWorld):
return world
@classmethod
def random(cls, **kwargs):
# TODO: fix the size keyword type (GridWorld expects Coordinates)
size = kwargs.get('size', 4)
seed = kwargs.get('seed', None)
pitProb = kwargs.get('pitProb', .2)
return cls.classic(size=size, seed=seed, pitProb=pitProb)
def random(cls, size: Union[int, Coordinate] = 4, seed=None, pitProb: float = .2, **kwargs):
return cls.classic(size=size, seed=seed, pitProb=pitProb, **kwargs)
@classmethod
def from_dict(cls, desc: Dict[str, Any]):
......@@ -279,7 +272,7 @@ class WumpusWorld(GridWorld):
else:
return [getCoord(data)]
size = coordLst('size')[0]
size = next(coordLst('size'))
blocks = coordLst('blocks')
hunters = desc.get('hunters', [])
pits = coordLst('pits')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment