Ejemplo n.º 1
0
 def __init__(self, name, piece):
     super(Builder, self).__init__()
     self._name = name
     self._piece = piece
     self._d24 = Server(PORT, 'Builder')
     self._d24.connect()
     self._d24.login()
Ejemplo n.º 2
0
 def __init__(self, rows, cols, piece):
     super(Guesser, self).__init__()
     self._rows = rows
     self._cols = cols
     self._piece = piece
     self._d24 = Server(PORT, 'Guesser')
     self._d24.connect()
     self._d24.login()
     self.stopit = False
Ejemplo n.º 3
0
 def __init__(self, name, piece, piece2, choices):
     super(Builder, self).__init__()
     self._name = name
     self._piece = piece
     self._piece2 = piece2
     self._choices = choices
     self._d24 = Server(PORT, 'Builder', HOST)
     self._d24.connect()
     self._d24.login()
Ejemplo n.º 4
0
class Builder(threading.Thread):
	def __init__(self, name, piece):
		super(Builder, self).__init__()
		self._name = name
		self._piece = piece
		self._d24 = Server(PORT, 'Builder')
		self._d24.connect()
		self._d24.login()

	def run(self):
		self._d24.debug('Running!')
		while True:
			resp = self._d24.command("CHANGES").split('\n')
			if resp[0] != self._name:
				break

			good = int(resp[2])
			for g in xrange(good):
				col, row, dcol, drow, drot, count = resp[3 + g].split()
				col = int(col) - 1
				row = int(row) - 1
				dcol = int(dcol) - 1
				drow = int(drow) - 1
				drot = int(drot)
				count = int(count[1:-1])
				self._piece[row][col] = (drow, dcol, count, drot)

		self._d24.debug('Closed!')
Ejemplo n.º 5
0
class Builder(threading.Thread):
    def __init__(self, name, piece):
        super(Builder, self).__init__()
        self._name = name
        self._piece = piece
        self._d24 = Server(PORT, 'Builder')
        self._d24.connect()
        self._d24.login()

    def run(self):
        self._d24.debug('Running!')
        while True:
            resp = self._d24.command("CHANGES").split('\n')
            if resp[0] != self._name:
                break

            good = int(resp[2])
            for g in xrange(good):
                col, row, dcol, drow, drot, count = resp[3 + g].split()
                col = int(col) - 1
                row = int(row) - 1
                dcol = int(dcol) - 1
                drow = int(drow) - 1
                drot = int(drot)
                count = int(count[1:-1])
                self._piece[row][col] = (drow, dcol, count, drot)

        self._d24.debug('Closed!')
Ejemplo n.º 6
0
 def __init__(self, rows, cols, piece, piece2, name, special):
     super(Guesser3, self).__init__()
     self._rows = rows
     self._cols = cols
     self._piece = piece
     self._piece2 = piece2
     self._name = name
     self._special = special
     self._d24 = Server(PORT, 'GuesserRandom', HOST)
     self._d24.connect()
     self._d24.login()
     self.stopit = False
Ejemplo n.º 7
0
	def __init__(self, id):
		super(Solver, self).__init__()
		self._id = id
		self._d24 = Server(20003, 'SOLVER %d' % id)
		self._d24.connect()
		self._d24.login()
		self._d24.debug('Started!')
		self.graph = [list()]
		self.weight = [0]
		self.timeLeft = 0
		self.orders = 0
		self.order = None
		self.done = True
		self.lastOrder = 0
Ejemplo n.º 8
0
	def __init__(self, name, piece):
		super(Builder, self).__init__()
		self._name = name
		self._piece = piece
		self._d24 = Server(PORT, 'Builder')
		self._d24.connect()
		self._d24.login()
Ejemplo n.º 9
0
class Builder(threading.Thread):
    def __init__(self, name, piece, piece2, choices):
        super(Builder, self).__init__()
        self._name = name
        self._piece = piece
        self._piece2 = piece2
        self._choices = choices
        self._d24 = Server(PORT, 'Builder', HOST)
        self._d24.connect()
        self._d24.login()

    def run(self):
        self._d24.debug('Running!')
        while True:
            resp = self._d24.command("CHANGES").split('\n')
            if resp[0] != self._name or not int(resp[1]):
                break

            good = int(resp[2])
            for g in xrange(good):
                col, row, dcol, drow, drot, count = resp[3 + g].split()
                col = int(col) - 1
                row = int(row) - 1
                dcol = int(dcol) - 1
                drow = int(drow) - 1
                drot = int(drot)
                count = int(count[1:-1])
                for i in (0, 90, 270, 280):
                    try:
                        self._choices.remove((row, col, drow, dcol, i))

                    except:
                        pass

                self._piece[row][col] = (drow, dcol, count, drot)
                self._piece2[drow][dcol] = (row, col, drot)
                if drow and not self._piece2[drow - 1][dcol]:
                    self._piece2[drow - 1][dcol] = False

                if dcol and not self._piece2[drow][dcol - 1]:
                    self._piece2[drow][dcol - 1] = False

                if dcol + 1 < len(
                        self._piece2[0]) and not self._piece2[drow][dcol + 1]:
                    self._piece2[drow][dcol + 1] = False

                if drow + 1 < len(
                        self._piece2) and not self._piece2[drow + 1][dcol]:
                    self._piece2[drow + 1][dcol] = False

        self._d24.debug('Closed!')
Ejemplo n.º 10
0
	def __init__(self, rows, cols, piece):
		super(Guesser, self).__init__()
		self._rows = rows
		self._cols = cols
		self._piece = piece
		self._d24 = Server(PORT, 'Guesser')
		self._d24.connect()
		self._d24.login()
		self.stopit = False
Ejemplo n.º 11
0
	def __init__(self, rows, cols, piece, piece2, name, special):
		super(Guesser3, self).__init__()
		self._rows = rows
		self._cols = cols
		self._piece = piece
		self._piece2 = piece2
		self._name = name
		self._special = special
		self._d24 = Server(PORT, 'GuesserRandom', HOST)
		self._d24.connect()
		self._d24.login()
		self.stopit = False
Ejemplo n.º 12
0
class Builder(threading.Thread):
	def __init__(self, name, piece, piece2):
		super(Builder, self).__init__()
		self._name = name
		self._piece = piece
		self._piece2 = piece2
		self._d24 = Server(PORT, 'Builder', HOST)
		self._d24.connect()
		self._d24.login()

	def run(self):
		self._d24.debug('Running!')
		while True:
			resp = self._d24.command("CHANGES").split('\n')
			if resp[0] != self._name or not int(resp[1]):
				break

			good = int(resp[2])
			for g in xrange(good):
				col, row, dcol, drow, drot, count = resp[3 + g].split()
				col = int(col) - 1
				row = int(row) - 1
				dcol = int(dcol) - 1
				drow = int(drow) - 1
				drot = int(drot)
				count = int(count[1:-1])
				self._piece[row][col] = (drow, dcol, count, drot)
				self._piece2[drow][dcol] = (row, col, drot)
				if drow and not self._piece2[drow - 1][dcol]:
					self._piece2[drow - 1][dcol] = False

				if dcol and not self._piece2[drow][dcol - 1]:
					self._piece2[drow][dcol -  1] = False

				if dcol + 1 < len(self._piece2[0]) and not self._piece2[drow][dcol + 1]:
					self._piece2[drow][dcol + 1] = False

				if drow + 1 < len(self._piece2) and not self._piece2[drow + 1][dcol]:
					self._piece2[drow + 1][dcol] = False

		self._d24.debug('Closed!')
Ejemplo n.º 13
0
class Guesser3(threading.Thread):
	def __init__(self, rows, cols, piece, piece2, name, special):
		super(Guesser3, self).__init__()
		self._rows = rows
		self._cols = cols
		self._piece = piece
		self._piece2 = piece2
		self._name = name
		self._special = special
		self._d24 = Server(PORT, 'GuesserRandom', HOST)
		self._d24.connect()
		self._d24.login()
		self.stopit = False

	def run(self):
		self._d24.debug('Running!')
		last = (0, 0, 0)
		while not self.stopit:
			From = []
			To = []
			for r in xrange(rows):
				for c in xrange(cols):
					if not self._piece[r][c][2]:
						From.append((r, c))

					if not self._piece2[r][c]:
						To.append((r, c))

			self._d24.debug('ZOSTALO: %d' % len(From))
			self._d24.debug('Z: %d, Do: %d' % (len(To), len(From)))
			a = random.choice(From)
			b = random.choice(To)
			rot = random.choice((0, 90, 180, 270))

			data = "%d %d %d %d %d" % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1, rot)

			try:
				if self._special[0]:
					self._d24.command("GUESS " + data)

			except Exception, msg:
				self._d24.debug(unicode(msg))

			self._d24.Wait()

		self._d24.debug('Closed!')
Ejemplo n.º 14
0
class Guesser2(threading.Thread):
	def __init__(self, rows, cols, piece, piece2, name, special):
		super(Guesser2, self).__init__()
		self._rows = rows
		self._cols = cols
		self._piece = piece
		self._piece2 = piece2
		self._name = name
		self._special = special
		self._d24 = Server(PORT, 'GuesserRandomHeura', HOST)
		self._d24.connect()
		self._d24.login()
		self.stopit = False

	def run(self):
		self._d24.debug('Running!')
		last = (0, 0, 0)
		while not self.stopit:
			From = []
			To = []
			for r in xrange(rows):
				for c in xrange(cols):
					if not self._piece[r][c][2]:
						From.append((r, c))

					if not self._piece2[r][c]:
						To.append((r, c))

			self._d24.debug('ZOSTALO: %d' % len(From))
			self._special[1] = True
			a, b, rot = checkNeighbours(self._name, self._piece2, random.sample(From, min(len(From), 16)))
			self._special[1] = False

			if a and b:
				self._d24.debug('HEURA: %d %d %d %d %d' % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1, rot))

			if not a or not b or (last[0] == a and last[1] == b and last[2] == rot):
				self._d24.debug('Z: %d, Do: %d' % (len(To), len(From)))
				a = random.choice(From)
				b = random.choice(To)
				rot = random.choice((0, 90, 180, 270))

			else:
				last = (a, b, rot)

			data = "%d %d %d %d %d" % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1, rot)

			try:
				if self._special[0]:
					self._d24.command("GUESS " + data)

			except Exception, msg:
				self._d24.debug(unicode(msg))

			self._d24.Wait()

		self._d24.debug('Closed!')
Ejemplo n.º 15
0
#d24 = x()
#mapa = [
	#[(0, 0, 0), (0, 1, 0), None, None],
	#[(1, 0, 0), None, None, None],
	#[None, None, None, None],
	#[None, None, None, None],
	#]

#divide(d24, 'gowno', 4, 4)
#
#print checkNeighbours('gowno', mapa, ((0, 2), (0, 3), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3), (3, 0), (3, 1), (3, 2), (3, 3)))
#
#
#sys.exit(0)

d24 = Server(PORT, 'Global', HOST)

d24.connect()
d24.login()

d24.debug('SZCZESCLIWY NUMEREK: %d' % os.getpid())
while True:
	try:
		memory.clear()
		# RUNDA
		name, password, cols, rows = d24.command("INFO").split();
		cols = int(cols)
		rows = int(rows)
		if password == "[WillShowOnNextTurn]":
			d24.Wait()
			continue
Ejemplo n.º 16
0
class Guesser(threading.Thread):
    def __init__(self, rows, cols, piece):
        super(Guesser, self).__init__()
        self._rows = rows
        self._cols = cols
        self._piece = piece
        self._d24 = Server(PORT, 'Guesser')
        self._d24.connect()
        self._d24.login()
        self.stopit = False

    def run(self):
        self._d24.debug('Running!')
        while not self.stopit:
            try:
                data = open('GUESS%d' % PORT, 'r').read()
                os.system('rm GUESS%d' % PORT)

            except Exception, msg:
                self._d24.debug(unicode(msg))
                From = []
                To = []
                free = emptyGrid2(rows, cols)
                for r in xrange(rows):
                    for c in xrange(cols):
                        if self._piece[r][c][2]:
                            free[self._piece[r][c][0]][self._piece[r][c]
                                                       [1]] = False

                        else:
                            From.append((r, c))

                for r in xrange(rows):
                    for c in xrange(cols):
                        if free[r][c]:
                            To.append((r, c))

                self._d24.debug('Z: %d, Do: %d' % (len(To), len(From)))
                a = random.choice(From)
                b = random.choice(To)
                data = "%d %d %d %d %d" % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] +
                                           1, random.choice((0, 90, 180, 270)))

            try:
                self._d24.command("GUESS " + data)

            except Exception, msg:
                self._d24.debug(unicode(msg))
Ejemplo n.º 17
0
class Guesser(threading.Thread):
	def __init__(self, rows, cols, piece):
		super(Guesser, self).__init__()
		self._rows = rows
		self._cols = cols
		self._piece = piece
		self._d24 = Server(PORT, 'Guesser')
		self._d24.connect()
		self._d24.login()
		self.stopit = False

	def run(self):
		self._d24.debug('Running!')
		while not self.stopit:
			try:
				data = open('GUESS%d' % PORT, 'r').read()
				os.system('rm GUESS%d' % PORT)

			except Exception, msg:
				self._d24.debug(unicode(msg))
				From = []
				To = []
				free = emptyGrid2(rows, cols)
				for r in xrange(rows):
					for c in xrange(cols):
						if self._piece[r][c][2]:
							free[self._piece[r][c][0]][self._piece[r][c][1]] = False

						else:
							From.append((r, c))

				for r in xrange(rows):
					for c in xrange(cols):
						if free[r][c]:
							To.append((r, c))

				self._d24.debug('Z: %d, Do: %d' % (len(To), len(From)))
				a = random.choice(From)
				b = random.choice(To)
				data = "%d %d %d %d %d" % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1, random.choice((0, 90, 180, 270)))

			try:
				self._d24.command("GUESS " + data)

			except Exception, msg:
				self._d24.debug(unicode(msg))
Ejemplo n.º 18
0
class Guesser3(threading.Thread):
    def __init__(self, rows, cols, piece, piece2, name, special):
        super(Guesser3, self).__init__()
        self._rows = rows
        self._cols = cols
        self._piece = piece
        self._piece2 = piece2
        self._name = name
        self._special = special
        self._d24 = Server(PORT, 'GuesserRandom', HOST)
        self._d24.connect()
        self._d24.login()
        self.stopit = False

    def run(self):
        self._d24.debug('Running!')
        last = (0, 0, 0)
        while not self.stopit:
            From = []
            To = []
            for r in xrange(rows):
                for c in xrange(cols):
                    if not self._piece[r][c][2]:
                        From.append((r, c))

                    if not self._piece2[r][c]:
                        To.append((r, c))

            self._d24.debug('ZOSTALO: %d' % len(From))
            self._d24.debug('Z: %d, Do: %d' % (len(To), len(From)))
            a = random.choice(From)
            b = random.choice(To)
            rot = random.choice((0, 90, 180, 270))

            data = "%d %d %d %d %d" % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1,
                                       rot)

            try:
                if self._special[0]:
                    self._d24.command("GUESS " + data)

            except Exception, msg:
                self._d24.debug(unicode(msg))

            self._d24.Wait()

        self._d24.debug('Closed!')
Ejemplo n.º 19
0
class Solver(object):
	def __init__(self, id):
		super(Solver, self).__init__()
		self._id = id
		self._d24 = Server(20003, 'SOLVER %d' % id)
		self._d24.connect()
		self._d24.login()
		self._d24.debug('Started!')
		self.graph = [list()]
		self.weight = [0]
		self.timeLeft = 0
		self.orders = 0
		self.order = None
		self.done = True
		self.lastOrder = 0

	def describeWorld(self):
		self.world = self._d24.command('DESCRIBE_WORLD')
		result = self.world.split('\n')
		self.world = hashlib.md5(self.world).hexdigest()
		res = result[0].split()
		self.verts, self.edges, self.time = map(int, res[:-1])
		self.scale = float(res[-1])
		self.graph = [list() for i in range(self.verts)]
		self.weight = [0] * self.verts
		self.lastOrder = 1
		for e in range(self.edges):
			start, end = map(lambda x: int(x) - 1, result[e + 1].split())
			self.graph[start].append(end)
			self.weight[start] += 1
			self.graph[end].append(start)
			self.weight[end] += 1

		return True

	def timeToCut(self):
		self.timeLeft = int(self._d24.command('TIME_TO_CUT'))
		return self.timeLeft

	def getOrderCount(self):
		self.orders = int(self._d24.command('GET_ORDER_COUNT'))
		return self.orders

	def describeOrder(self, id):
		try:
			result = self._d24.command('DESCRIBE_ORDER %d' % id).split('\n')

		except deadline24.CommandError, e:
			self._d24.debug(e)
			return False

		res = result[0].split()
		self.order = {}
		self.order['id'] = id
		self.order['verts'], self.order['edges'], self.order['cost'], self.order['teams'] = int(res[0]), int(res[1]), float(res[2]), int(res[3])
		self.order['graph'] = graph = [list() for i in range(self.verts)]
		self.order['pygraph'] = pgraph = Graph()
		for v in range(self.order['verts']):
			pgraph.add_node(v)

		self.order['weight'] = weight = [0] * self.order['verts']
		self.order['result'] = list(range(self.order['verts']))
		for e in range(self.order['edges']):
			start, end = map(lambda x: int(x) - 1, result[e + 1].split())
			pgraph.add_edge((start, end))
			graph[start].append(end)
			weight[start] += 1
			graph[end].append(start)
			weight[end] += 1

		return True
Ejemplo n.º 20
0
class Guesser3(threading.Thread):
    def __init__(self, rows, cols, piece, piece2, name, special, choices):
        super(Guesser3, self).__init__()
        self._rows = rows
        self._cols = cols
        self._piece = piece
        self._piece2 = piece2
        self._name = name
        self._special = special
        self._choices = choices
        self._d24 = Server(PORT, 'GuesserRandom', HOST)
        self._d24.connect()
        self._d24.login()
        self.stopit = False

    def run(self):
        self._d24.debug('Running!')
        while not self.stopit:
            self._d24.debug('ZOSTALO: %d' % len(self._choices))
            seq = random.choice(self._choices)
            data = "%d %d %d %d %d" % (seq[1] + 1, seq[0] + 1, seq[3] + 1,
                                       seq[2] + 1, seq[4])

            try:
                if self._special[0]:
                    self._d24.command("GUESS " + data)
                    try:
                        self._choices.remove(seq)

                    except:
                        pass

            except Exception, msg:
                self._d24.debug(unicode(msg))

            self._d24.Wait()

        self._d24.debug('Closed!')
Ejemplo n.º 21
0
class Guesser2(threading.Thread):
    def __init__(self, rows, cols, piece, piece2, name, special, choices):
        super(Guesser2, self).__init__()
        self._rows = rows
        self._cols = cols
        self._piece = piece
        self._piece2 = piece2
        self._name = name
        self._special = special
        self._choices = choices
        self._d24 = Server(PORT, 'GuesserRandomHeura', HOST)
        self._d24.connect()
        self._d24.login()
        self.stopit = False

    def run(self):
        self._d24.debug('Running!')
        last = (0, 0, 0)
        while not self.stopit:
            From = []
            for r in xrange(rows):
                for c in xrange(cols):
                    if not self._piece[r][c][2]:
                        From.append((r, c))

            self._d24.debug('ZOSTALO: %d' % len(From))
            self._special[1] = True
            a, b, rot = checkNeighbours(
                self._name, self._piece2,
                random.sample(From, min(len(From), 16)))
            self._special[1] = False

            if a and b:
                self._d24.debug('HEURA: %d %d %d %d %d' %
                                (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1, rot))
                seq = (a[0], a[1], b[0], b[1], rot)
                if not seq in self._choices:
                    a = None

            if not a or not b or (last[0] == a and last[1] == b
                                  and last[2] == rot):
                seq = random.choice(self._choices)

            else:
                last = (a, b, rot)

            data = "%d %d %d %d %d" % (seq[1] + 1, seq[0] + 1, seq[3] + 1,
                                       seq[2] + 1, seq[4])

            try:
                if self._special[0]:
                    self._d24.command("GUESS " + data)
                    try:
                        self._choices.remove(seq)

                    except:
                        pass

            except Exception, msg:
                self._d24.debug(unicode(msg))

            self._d24.Wait()

        self._d24.debug('Closed!')
Ejemplo n.º 22
0
#d24 = x()
#mapa = [
#[(0, 0, 0), (0, 1, 0), None, None],
#[(1, 0, 0), None, None, None],
#[None, None, None, None],
#[None, None, None, None],
#]

#divide(d24, 'gowno', 4, 4)
#
#print checkNeighbours('gowno', mapa, ((0, 2), (0, 3), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3), (3, 0), (3, 1), (3, 2), (3, 3)))
#
#
#sys.exit(0)

d24 = Server(PORT, 'Global', HOST)

d24.connect()
d24.login()

d24.debug('SZCZESCLIWY NUMEREK: %d' % os.getpid())
while True:
    try:
        memory.clear()
        # RUNDA
        name, password, cols, rows = d24.command("INFO").split()
        if password == "[WillShowOnNextTurn]":
            d24.Wait()
            continue

        cols = int(cols)
Ejemplo n.º 23
0
            for g in xrange(good):
                col, row, dcol, drow, drot, count = resp[3 + g].split()
                col = int(col) - 1
                row = int(row) - 1
                dcol = int(dcol) - 1
                drow = int(drow) - 1
                drot = int(drot)
                count = int(count[1:-1])
                self._piece[row][col] = (drow, dcol, count, drot)

        self._d24.debug('Closed!')


##########################################################################

d24 = Server(PORT, 'Global')

d24.connect()
d24.login()

d24.debug('SZCZESCLIWY NUMEREK: %d' % os.getpid())
while True:
    if True:
        #try:
        # RUNDA
        name, password, cols, rows = d24.command("INFO").split()
        cols = int(cols)
        rows = int(rows)
        if password == "[WillShowOnNextTurn]":
            d24.command('WAIT')
            continue
Ejemplo n.º 24
0
class Guesser(threading.Thread):
    def __init__(self, rows, cols, piece, piece2, name, special):
        super(Guesser, self).__init__()
        self._rows = rows
        self._cols = cols
        self._piece = piece
        self._piece2 = piece2
        self._name = name
        self._special = special
        self._d24 = Server(PORT, 'Guesser', HOST)
        self._d24.connect()
        self._d24.login()
        self.stopit = False

    def run(self):
        self._d24.debug('Running!')
        last = (0, 0, 0)
        while not self.stopit:
            From = []
            To = []
            for r in xrange(rows):
                for c in xrange(cols):
                    if not self._piece[r][c][2]:
                        From.append((r, c))

                    if not self._piece2[r][c]:
                        To.append((r, c))

            self._d24.debug('ZOSTALO: %d' % len(From))
            random.shuffle(From)
            self._special[0] = True
            a, b, rot = checkNeighbours(self._name, self._piece2, From)
            if a:
                a = tuple(a)

            if b:
                b = tuple(b)

            self._special[0] = False
            if a and b:
                self._d24.debug('HEURA: %d %d %d %d %d' %
                                (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1, rot))

            if not a or not b or (last[0] == a and last[1] == b
                                  and last[2] == rot):
                self._d24.debug('Z: %d, Do: %d' % (len(To), len(From)))
                a = random.choice(From)
                b = random.choice(To)
                rot = random.choice((0, 90, 180, 270))

            else:
                last = (a, b, rot)

            data = "%d %d %d %d %d" % (a[1] + 1, a[0] + 1, b[1] + 1, b[0] + 1,
                                       rot)

            try:
                self._d24.command("GUESS " + data)

            except Exception, msg:
                self._d24.debug(unicode(msg))

            time.sleep(0.6)

        self._d24.debug('Closed!')