Skip to content

Commit 6980ebf

Browse files
committed
Convert into a python package with separate tests
1 parent 593cfcb commit 6980ebf

30 files changed

+95
-54
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "aima-data"]
2-
path = aima-data
1+
[submodule "aimaPy/aima-data"]
2+
path = aimaPy/aima-data
33
url = https://github.com/aimacode/aima-data

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
graft aimaPy/aima-data
2+
graft aimaPy/images

aimaPy/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from . import agents
2+
from . import csp
3+
from . import games
4+
from . import grid
5+
from . import learning
6+
from . import logic
7+
from . import mdp
8+
from . import nlp
9+
from . import planning
10+
from . import probability
11+
from . import rl
12+
from . import search
13+
from . import text
14+
from . import utils

agents.py renamed to aimaPy/agents.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#
3636
# Speed control in GUI does not have any effect -- fix it.
3737

38-
from utils import *
38+
from . utils import *
3939
import random
4040
import copy
4141
import collections
@@ -102,7 +102,7 @@ def TraceAgent(agent):
102102

103103
def new_program(percept):
104104
action = old_program(percept)
105-
print(('{} perceives {} and does {}'.format(agent, percept, action)))
105+
print('{} perceives {} and does {}'.format(agent, percept, action))
106106
return action
107107
agent.program = new_program
108108
return agent
@@ -304,10 +304,9 @@ def delete_thing(self, thing):
304304
except(ValueError, e):
305305
print(e)
306306
print(" in Environment delete_thing")
307-
print(
308-
(" Thing to be removed: {} at {}" .format(thing, thing.location)))
309-
print((" from list: {}" .format([(thing, thing.location)
310-
for thing in self.things])))
307+
print(" Thing to be removed: {} at {}" .format(thing, thing.location))
308+
print(" from list: {}" .format([(thing, thing.location)
309+
for thing in self.things]))
311310
if thing in self.agents:
312311
self.agents.remove(thing)
313312

aimaPy/aima-data

Submodule aima-data added at 5b0526a

csp.py renamed to aimaPy/csp.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""CSP (Constraint Satisfaction Problems) problems and solvers. (Chapter 6)."""
22

33

4-
from utils import *
4+
from . utils import *
55
from collections import defaultdict
6-
import search
6+
from . import search
77
from functools import reduce
88

99

@@ -519,6 +519,17 @@ def flatten(seqs): return sum(seqs, [])
519519
easy1 = '..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..'
520520
harder1 = '4173698.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......'
521521

522+
_R3 = list(range(3))
523+
_CELL = itertools.count().__next__
524+
_BGRID = [[[[_CELL() for x in _R3] for y in _R3] for bx in _R3] for by in _R3]
525+
_BOXES = flatten([list(map(flatten, brow)) for brow in _BGRID])
526+
_ROWS = flatten([list(map(flatten, list(zip(*brow)))) for brow in _BGRID])
527+
_COLS = list(zip(*_ROWS))
528+
529+
_NEIGHBORS = dict([(v, set()) for v in flatten(_ROWS)])
530+
for unit in map(set, _BOXES + _ROWS + _COLS):
531+
for v in unit:
532+
_NEIGHBORS[v].update(unit - set([v]))
522533

523534
class Sudoku(CSP):
524535

@@ -556,17 +567,13 @@ class Sudoku(CSP):
556567
>>> None != backtracking_search(h, select_unassigned_variable=mrv, inference=forward_checking)
557568
True
558569
"""
559-
R3 = list(range(3))
560-
Cell = itertools.count().__next__
561-
bgrid = [[[[Cell() for x in R3] for y in R3] for bx in R3] for by in R3]
562-
boxes = flatten([list(map(flatten, brow)) for brow in bgrid])
563-
rows = flatten([list(map(flatten, list(zip(*brow)))) for brow in bgrid])
564-
cols = list(zip(*rows))
565-
566-
neighbors = dict([(v, set()) for v in flatten(rows)])
567-
for unit in map(set, boxes + rows + cols):
568-
for v in unit:
569-
neighbors[v].update(unit - set([v]))
570+
R3 = _R3
571+
Cell = _CELL
572+
bgrid = _BGRID
573+
boxes = _BOXES
574+
rows = _ROWS
575+
cols = _COLS
576+
neighbors = _NEIGHBORS
570577

571578
def __init__(self, grid):
572579
"""Build a Sudoku problem from a string representing the grid:

games.py renamed to aimaPy/games.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33

44

5-
from utils import *
5+
from . utils import *
66
import random
77

88
#______________________________________________________________________________
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)