Exemple #1
0
 def getNeighborCell(self,current, heuristic):
   cells = []
   if current.getX()-1 >= 0 and self.getCell(self.world,current.getX()-1,current.getY()) != 1:
     cells.append(cell(current.getX()-1, current.getY(), current, self.getCell(heuristic,current.getX()-1,current.getY())))
   if current.getX()+1 <= self.mapSize-1 and self.getCell(self.world,current.getX()+1,current.getY()) != 1:
     cells.append(cell(current.getX()+1, current.getY(), current, self.getCell(heuristic,current.getX()+1,current.getY())))
   if current.getY()-1 >= 0 and self.getCell(self.world,current.getX(),current.getY()-1) != 1:
     cells.append(cell(current.getX(), current.getY()-1, current, self.getCell(heuristic,current.getX(),current.getY()-1)))
   if current.getY()+1 <= self.mapSize-1 and self.getCell(self.world,current.getX(),current.getY()+1) != 1:
     cells.append(cell(current.getX(), current.getY()+1, current, self.getCell(heuristic,current.getX(),current.getY()+1)))
   return cells
Exemple #2
0
	def fill(self,ran):
		for i in xrange(self.map_size):
			self.map.append([])
			for g in xrange(self.map_size):
				if ran == True:
					a = random.randint(0,4)
					if a == 0: 
						self.map[i].insert(g,cell((i,g),Compartment.infected, self.number_generations_to_be_recovered, self.number_generations_to_be_infected, self.probability_to_infection, self.probability_to_cure))
					else: 
						self.map[i].insert(g,cell((i,g), Compartment.susceptible,self.number_generations_to_be_recovered, self.number_generations_to_be_infected, self.probability_to_infection, self.probability_to_cure))	
				else: 
					self.map[i].insert(g,cell((i,g),Compartment.susceptible,self.number_generations_to_be_recovered, self.number_generations_to_be_infected, self.probability_to_infection, self.probability_to_cure))
Exemple #3
0
    def __init__(self):
        """Creates the board"""
        self.current_move = Colors.Free
        self.ready_for_castling = False
        self.shah = False
        self.board = [[cell((i, j)) for i in range(8)] for j in range(8)]
        for i in (1, 6):
            for j in range(8):
                self.board[i][j].piece_type = Pawn(Colors.White if i ==
                                                   1 else Colors.Black)

        for i in (0, 7):
            self.board[i][0].piece_type = Rook(Colors.White if i ==
                                               0 else Colors.Black)
            self.board[i][7].piece_type = Rook(Colors.White if i ==
                                               0 else Colors.Black)
            self.board[i][1].piece_type = Knight(Colors.White if i ==
                                                 0 else Colors.Black)
            self.board[i][6].piece_type = Knight(Colors.White if i ==
                                                 0 else Colors.Black)
            self.board[i][2].piece_type = Bishop(Colors.White if i ==
                                                 0 else Colors.Black)
            self.board[i][5].piece_type = Bishop(Colors.White if i ==
                                                 0 else Colors.Black)
            self.board[i][4].piece_type = King(Colors.White if i ==
                                               0 else Colors.Black)
            self.board[i][3].piece_type = Queen(Colors.White if i ==
                                                0 else Colors.Black)
        for i in range(2, 6):
            for j in range(8):
                self.board[i][j].piece_type = Free_space()
Exemple #4
0
def empty_board(h, w, N):
    # Takes a window width w and height h and generates an N sized Sudoku board
    # (N being a square number, default = 9, hardcorded for now)
    # returning board, a grid of cell objects with indexing of form cells[i][j]

    eBoard = [[], [], [], [], [], [], [], [], []]

    # Initialise empty board
    for yindex in range(int((w / 50))):
        row = []
        for xindex in range(int((w / 50))):
            row.append(cell(xindex * 50, yindex * 50, 50, 50))
        eBoard[yindex] = row
    return eBoard
Exemple #5
0
 def idaStarSearch(self, heuristic):
   #start cell
   rootNode = cell(self.startPoint[0],self.startPoint[1],None,self.getCell(heuristic,self.startPoint[0],self.startPoint[1]))
   costLimit = rootNode.getH()
   self.idaStarNodes = 0
   it = 0
   while True:
     it+=1
     #logging.debug("Iteration:"+str(it))
     (solution, costLimit) = self.DFS(0, rootNode, costLimit, [rootNode],heuristic)
     if solution != None:
       return len(solution)
       #return (solution, costLimit)
     if costLimit == Infinity:
       logging.error("Path with IDA* was not found!")
       return None
Exemple #6
0
 def aStarSearch(self,heuristic):
   #in open list we put cells that we are going to look
   #in closed list we put tuple (x,y) coordinates of cells that we already looked
   openList = set()
   closedList = set()
   #closed list with F value, for reopening nodes in closed list
   closedListTemp = set()
   #current - start cell
   current = cell(self.startPoint[0],self.startPoint[1],None,self.getCell(heuristic,self.startPoint[0],self.startPoint[1]))
   openList.add(current)
   
   while openList:
     #temp = sorted(openList, key = lambda cell:cell.getG(), reverse=True)
     current = sorted(openList, key = lambda cell:cell.getF())[0]
     
     if current.getXY() == self.finishPoint:
       self.aStarCheckedNodes = len(closedList)
       self.aStarOpenNodes = len(openList)
       return self.getAStarPathLength(current)
       
     openList.remove(current)
     closedList.add(current.getXY())
     closedListTemp.add(current.getXYF())
     neighbors = self.getNeighborCell(current, heuristic)
     for n in neighbors:
       if n.getXY() in closedList:
         #go through closed list with F values and compare F of the same nodes
         for t in closedListTemp:
           if t[0] == n.getX() and t[1] == n.getY():
             #check if we can reopen node
             if n.getF() < t[2]:
               openList.add(n)
               closedList.remove(n.getXY())
               break
       else:
         openList.add(n)
   print "Fail to find path"
   return -1
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from Cell import cell
from datetime import datetime, timedelta
from dateutil.parser import parse

# Init cells
cell1 = cell('cell1', 1)
cell2 = cell('cell2', 2)
cell3 = cell('cell3', 2)
cell4 = cell('cell4', 3)

# Iteration by time
def compareCells(cell1, cell2):
    startdate = parse(cell1.getStartDate())
    enddate = parse(cell1.getEndDate())
    while (startdate < enddate):
        print(startdate)
        # do the magic here
        startdate = startdate + timedelta(minutes=15)


compareCells(cell1, cell2)
Exemple #8
0
 def __init__(self, infos=None):
     super().__init__()
     self.centeral = cell(site=[0, 0], info=infos)
     self.MetalList = ['gold', 'sliver', 'iron', 'copper']
     self.yourMetal = {'gold': 0, 'sliver': 0, 'iron': 0, 'copper': 0}