From ad73fcffe1cca10530563fdabf8a148c6599958f Mon Sep 17 00:00:00 2001 From: Sydriax Date: Wed, 31 Aug 2016 18:36:43 -0400 Subject: [PATCH 1/8] more maze stuff --- problems/maze/run_game.py | 61 +++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/problems/maze/run_game.py b/problems/maze/run_game.py index 2bea701..37d7f52 100644 --- a/problems/maze/run_game.py +++ b/problems/maze/run_game.py @@ -1,30 +1,73 @@ import socket, json +# Directions +NORTH = 0 +EAST = 1 +SOUTH = 2 +WEST = 3 + +# Tile states UNKNOWN = 0 -EMPTY = 1 -WALL = 2 -GOAL = 3 -PLAYER = 4 +EMPTY = 1 # transparent +WALL = 2 # opaque +GLASS = 3 # transparent +GOAL = 4 # transparent +PLAYER = 5 + +class Point: + def __init__(self, x = 0, y = 0): + self.x = x + self.y = y class Map: def __init__(self, width, height, seed): self.contents = [] + self.visibility = [] for y in range(0, height): - row = [] + contents_row = [] + visibility_row = [] for x in range(0, width): - row.append((EMPTY, False)) # Full of empty yet unseen squares. - self.contents.append(row) + contents_row.append(EMPTY) # Full of empty squares to start. + visibility_row.append(True) + self.contents.append(contents_row) + self.visibility.append(visibility_row) + self.contents[0][0] = PLAYER + + def make_move(self, dir): + player_loc = None + for y in range(0, len(self.contents)): + for x in range(0, len(self.contents[0])): + if self.contents[y][x] == PLAYER: + player_loc = (x, y) + self.contents[y][x] = EMPTY + if dir == NORTH and player_loc[1] != 0 and (self.contents[player_loc[1]-1][player_loc[0]] == EMPTY or self.contents[player_loc[1]-1][player_loc[0]] == GOAL): + player_loc = (player_loc[0], player_loc[1]-1) + elif dir == EAST and player_loc[0] != len(self.contents[0])-1 and (self.contents[player_loc[1]][player_loc[0]+1] == EMPTY or self.contents[player_loc[1]][player_loc[0]+1] == GOAL): + player_loc = (player_loc[0]+1, player_loc[1]) + elif dir == SOUTH and player_loc[1] != len(self.contents)-1 and (self.contents[player_loc[1]+1][player_loc[0]] == EMPTY or self.contents[player_loc[1]+1][player_loc[0]] == GOAL): + player_loc = (player_loc[0], player_loc[1]+1) + elif dir == WEST and player_loc[0] != 0 and (self.contents[player_loc[1]][player_loc[0]-1] == EMPTY or self.contents[player_loc[1]][player_loc[0]-1] == GOAL): + player_loc = (player_loc[0]-1, player_loc[1]) + if self.contents[player_loc[1]][player_loc[0]] == GOAL: + return True + self.contents[player_loc[1]][player_loc[0]] = PLAYER + return False + + def update_visibility(self): + x=0 + def serialize(self): grid = [] for y in range(0, len(self.contents)): row = [] for x in range(0, len(self.contents[0])): - if self.contents[y][x][1]: - row.append(self.contents[y][x][0]) + if self.visibility[y][x]: + row.append(self.contents[y][x]) else: row.append(UNKNOWN) grid.append(row) return json.dumps(grid) m = Map(5, 5, 0) +m.make_move(SOUTH) print(m.serialize()) From 6f12b65c1cc5856523e48078e3f6b5d1b509e63b Mon Sep 17 00:00:00 2001 From: joshuagruenstein Date: Fri, 2 Sep 2016 09:45:59 -0400 Subject: [PATCH 2/8] maze networking --- problems/maze/env/main.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 problems/maze/env/main.py diff --git a/problems/maze/env/main.py b/problems/maze/env/main.py new file mode 100644 index 0000000..96c71e9 --- /dev/null +++ b/problems/maze/env/main.py @@ -0,0 +1,17 @@ +from flask import Flask, request +import json +import random + +app = Flask(__name__) + +@app.route('/start') +def start(): + key = ''.join(random.choice('0123456789ABCDEF') for i in range(16)) + return key + +@app.route('/move/') +def move(move): + return str(move) + +if __name__ == '__main__': + app.run(host='0.0.0.0',port=7500,debug=True) From 2b6232a707294067132d0725e542348c9f0dac0e Mon Sep 17 00:00:00 2001 From: Sydriax Date: Fri, 2 Sep 2016 10:47:14 -0400 Subject: [PATCH 3/8] Wrote visibility code and main loop --- problems/maze/run_game.py | 145 ++++++++++++++++++++++++++++++-------- 1 file changed, 116 insertions(+), 29 deletions(-) diff --git a/problems/maze/run_game.py b/problems/maze/run_game.py index 37d7f52..acb60ec 100644 --- a/problems/maze/run_game.py +++ b/problems/maze/run_game.py @@ -1,4 +1,4 @@ -import socket, json +import socket, json, collections, time, sys # Directions NORTH = 0 @@ -14,53 +14,128 @@ GOAL = 4 # transparent PLAYER = 5 +# The following class and functions are for testing visibility. class Point: def __init__(self, x = 0, y = 0): self.x = x self.y = y + def __repr__(self): + return '(' + str(self.x) + ', ' + str(self.y) + ')' + def __eq__(self, other): + return self.x == other.x and self.y == other.y + def __key(self): + return (self.x, self.y) + def __hash__(self): + return hash(self.__key()) +def get_orientation(p1, p2, p3): + val = (p2.y - p1.y) * (p3.x - p2.x) - (p2.x - p1.x) * (p3.y - p2.y) + if val == 0: return 0 + if val > 0: return 1 + return -1 +def col_is_on_seg(p1, p2, test): + return test.x >= min(p1.x, p2.x) and test.x <= max(p1.x, p2.x) and test.y >= min(p1.y, p2.y) and test.y <= max(p1.y, p2.y) +def does_intersect(l1, l2): + o1 = get_orientation(l1[0], l1[1], l2[0]) + o2 = get_orientation(l1[0], l1[1], l2[1]) + o3 = get_orientation(l2[0], l2[1], l1[0]) + o4 = get_orientation(l2[0], l2[1], l1[1]) + if o1 != o2 and o3 != o4: return True + if o1 == 0 and col_is_on_seg(l1[0], l1[1], l2[0]): return True + if o2 == 0 and col_is_on_seg(l1[0], l1[1], l2[1]): return True + if o3 == 0 and col_is_on_seg(l2[0], l2[1], l1[0]): return True + if o4 == 0 and col_is_on_seg(l2[0], l2[1], l1[1]): return True + return False class Map: def __init__(self, width, height, seed): + self.height = height + self.width = width self.contents = [] self.visibility = [] - for y in range(0, height): + for y in range(0, self.height): contents_row = [] visibility_row = [] - for x in range(0, width): + for x in range(0, self.width): contents_row.append(EMPTY) # Full of empty squares to start. - visibility_row.append(True) + visibility_row.append(False) self.contents.append(contents_row) self.visibility.append(visibility_row) self.contents[0][0] = PLAYER - + self.player_loc = (0, 0) + self.opaque_walls = [] # We'll use these for finding what walls are opaque. + # We'll also assume that every square is 1x1, as it doesn't matter. + self.contents[2][2] = WALL # for testing + self.contents[2][3] = WALL # for testing + for y in range(0, self.height): + for x in range(0, self.width): + if self.contents[y][x] == WALL: + self.opaque_walls.append((Point(x, y), Point(x, y+1))) + self.opaque_walls.append((Point(x, y), Point(x+1, y))) + self.opaque_walls.append((Point(x+1, y), Point(x+1, y+1))) + self.opaque_walls.append((Point(x, y+1), Point(x+1, y+1))) + self.opaque_walls = set(self.opaque_walls) def make_move(self, dir): - player_loc = None - for y in range(0, len(self.contents)): - for x in range(0, len(self.contents[0])): - if self.contents[y][x] == PLAYER: - player_loc = (x, y) - self.contents[y][x] = EMPTY - if dir == NORTH and player_loc[1] != 0 and (self.contents[player_loc[1]-1][player_loc[0]] == EMPTY or self.contents[player_loc[1]-1][player_loc[0]] == GOAL): - player_loc = (player_loc[0], player_loc[1]-1) - elif dir == EAST and player_loc[0] != len(self.contents[0])-1 and (self.contents[player_loc[1]][player_loc[0]+1] == EMPTY or self.contents[player_loc[1]][player_loc[0]+1] == GOAL): - player_loc = (player_loc[0]+1, player_loc[1]) - elif dir == SOUTH and player_loc[1] != len(self.contents)-1 and (self.contents[player_loc[1]+1][player_loc[0]] == EMPTY or self.contents[player_loc[1]+1][player_loc[0]] == GOAL): - player_loc = (player_loc[0], player_loc[1]+1) - elif dir == WEST and player_loc[0] != 0 and (self.contents[player_loc[1]][player_loc[0]-1] == EMPTY or self.contents[player_loc[1]][player_loc[0]-1] == GOAL): - player_loc = (player_loc[0]-1, player_loc[1]) - if self.contents[player_loc[1]][player_loc[0]] == GOAL: - return True - self.contents[player_loc[1]][player_loc[0]] = PLAYER + self.contents[self.player_loc[1]][self.player_loc[0]] = EMPTY + if dir == NORTH and self.player_loc[1] != 0 and (self.contents[self.player_loc[1]-1][self.player_loc[0]] == EMPTY or self.contents[self.player_loc[1]-1][self.player_loc[0]] == GOAL): + self.player_loc = (self.player_loc[0], self.player_loc[1]-1) + elif dir == EAST and self.player_loc[0] != self.width-1 and (self.contents[self.player_loc[1]][self.player_loc[0]+1] == EMPTY or self.contents[self.player_loc[1]][self.player_loc[0]+1] == GOAL): + self.player_loc = (self.player_loc[0]+1, self.player_loc[1]) + elif dir == SOUTH and self.player_loc[1] != self.height-1 and (self.contents[self.player_loc[1]+1][self.player_loc[0]] == EMPTY or self.contents[self.player_loc[1]+1][self.player_loc[0]] == GOAL): + self.player_loc = (self.player_loc[0], self.player_loc[1]+1) + elif dir == WEST and self.player_loc[0] != 0 and (self.contents[self.player_loc[1]][self.player_loc[0]-1] == EMPTY or self.contents[self.player_loc[1]][self.player_loc[0]-1] == GOAL): + self.player_loc = (self.player_loc[0]-1, self.player_loc[1]) + if self.contents[self.player_loc[1]][self.player_loc[0]] == GOAL: return True + self.contents[self.player_loc[1]][self.player_loc[0]] = PLAYER + return False + def get_neighbors(self, loc): + neighbors = [] + if loc[1] != 0: neighbors.append((loc[0], loc[1]-1)) + if loc[0] != self.width-1: neighbors.append((loc[0]+1, loc[1])) + if loc[1] != self.height-1: neighbors.append((loc[0], loc[1]+1)) + if loc[0] != 0: neighbors.append((loc[0]-1, loc[1])) + return neighbors + def test_visible(self, loc): + corners = [ Point(loc[0], loc[1]),Point(loc[0]+1, loc[1]),Point(loc[0], loc[1]+1),Point(loc[0]+1, loc[1]+1) ] + center = Point(self.player_loc[0]+0.5, self.player_loc[1]+0.5) + for p in corners: + is_good = True + for wall in self.opaque_walls: + if wall[0] == p or wall[1] == p: + continue + if does_intersect(wall, (p, center)): + is_good = False + break + if is_good: + return True return False - def update_visibility(self): - x=0 - + # Ensure that the squares directly adjacent to the player are visible. + for loc in self.get_neighbors(self.player_loc): + self.visibility[loc[1]][loc[0]] = True + bfs = collections.deque() + for y in range(0, self.height): + for x in range(0, self.width): + if self.visibility[y][x]: + bfs.appendleft((x, y)) + while len(bfs) > 0: + # We're going to use an additional value, -1, to mark tiles we've visited and confirmed are invisible this turn. + loc = bfs.pop() + for n in self.get_neighbors(loc): + if self.visibility[n[1]][n[0]] == False: + if self.test_visible(n): + self.visibility[n[1]][n[0]] = True + bfs.appendleft(n) + else: + self.visibility[n[1]][n[0]] = -1 + for y in range(0, self.height): + for x in range(0, self.width): + if self.visibility[y][x] == -1: + self.visibility[y][x] = False def serialize(self): grid = [] - for y in range(0, len(self.contents)): + for y in range(0, self.height): row = [] - for x in range(0, len(self.contents[0])): + for x in range(0, self.width): if self.visibility[y][x]: row.append(self.contents[y][x]) else: @@ -68,6 +143,18 @@ def serialize(self): grid.append(row) return json.dumps(grid) +MAX_SEC = 60 + m = Map(5, 5, 0) -m.make_move(SOUTH) -print(m.serialize()) +start_time = time.time(); +game_over = False +while not game_over: + m.update_visibility() + send_string(m.serialize()) + try: + move = get_move(MAX_SEC + start_time - time.time()) + game_over = m.make_move(move) + except Exception: + print(-1) + sys.exit(0) +print(time.time() - start_time) From 5d4f24027a298d26a3eb214c440d2e30778ba439 Mon Sep 17 00:00:00 2001 From: Sydriax Date: Mon, 5 Sep 2016 11:55:19 -0400 Subject: [PATCH 4/8] Maze env improvements --- .atom-build.yml | 1 + problems/maze/env/main.py | 15 ++++++++-- problems/maze/{run_game.py => env/maze.py} | 33 ++++++++-------------- 3 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 .atom-build.yml rename problems/maze/{run_game.py => env/maze.py} (93%) diff --git a/.atom-build.yml b/.atom-build.yml new file mode 100644 index 0000000..0a677b2 --- /dev/null +++ b/.atom-build.yml @@ -0,0 +1 @@ +cmd: python3 problems/maze/run_game.py diff --git a/problems/maze/env/main.py b/problems/maze/env/main.py index 96c71e9..de6fe4d 100644 --- a/problems/maze/env/main.py +++ b/problems/maze/env/main.py @@ -2,16 +2,25 @@ import json import random +games = {} + app = Flask(__name__) @app.route('/start') def start(): key = ''.join(random.choice('0123456789ABCDEF') for i in range(16)) + games[key] = Map(21, 21, random.randint(0, 4294967295)) return key -@app.route('/move/') -def move(move): - return str(move) +@app.route('/move/') +def move(key, move): + result = games[key].make_move(move) + if result != 0: + del games[key] + return result + games[key].update_visibility() + games[key].delay() + send_string(games[key].serialize()) # Josh, I'm assuming that 'send_string' exists, because I have no idea how you want it to be written. if __name__ == '__main__': app.run(host='0.0.0.0',port=7500,debug=True) diff --git a/problems/maze/run_game.py b/problems/maze/env/maze.py similarity index 93% rename from problems/maze/run_game.py rename to problems/maze/env/maze.py index acb60ec..6793703 100644 --- a/problems/maze/run_game.py +++ b/problems/maze/env/maze.py @@ -14,6 +14,10 @@ GOAL = 4 # transparent PLAYER = 5 +# Max amount of time for player to respond. +MAX_SEC = 60 +MIN_DELAY = 0.025 + # The following class and functions are for testing visibility. class Point: def __init__(self, x = 0, y = 0): @@ -46,7 +50,7 @@ def does_intersect(l1, l2): if o4 == 0 and col_is_on_seg(l2[0], l2[1], l1[1]): return True return False -class Map: +class Maze: def __init__(self, width, height, seed): self.height = height self.width = width @@ -74,6 +78,7 @@ def __init__(self, width, height, seed): self.opaque_walls.append((Point(x+1, y), Point(x+1, y+1))) self.opaque_walls.append((Point(x, y+1), Point(x+1, y+1))) self.opaque_walls = set(self.opaque_walls) + self.start_time = time.time() def make_move(self, dir): self.contents[self.player_loc[1]][self.player_loc[0]] = EMPTY if dir == NORTH and self.player_loc[1] != 0 and (self.contents[self.player_loc[1]-1][self.player_loc[0]] == EMPTY or self.contents[self.player_loc[1]-1][self.player_loc[0]] == GOAL): @@ -84,17 +89,17 @@ def make_move(self, dir): self.player_loc = (self.player_loc[0], self.player_loc[1]+1) elif dir == WEST and self.player_loc[0] != 0 and (self.contents[self.player_loc[1]][self.player_loc[0]-1] == EMPTY or self.contents[self.player_loc[1]][self.player_loc[0]-1] == GOAL): self.player_loc = (self.player_loc[0]-1, self.player_loc[1]) - if self.contents[self.player_loc[1]][self.player_loc[0]] == GOAL: return True + if self.contents[self.player_loc[1]][self.player_loc[0]] == GOAL: return 1 self.contents[self.player_loc[1]][self.player_loc[0]] = PLAYER - return False - def get_neighbors(self, loc): + return 0 if time.time() - self.start_time < MAX_SEC else -1 + def _get_neighbors(self, loc): neighbors = [] if loc[1] != 0: neighbors.append((loc[0], loc[1]-1)) if loc[0] != self.width-1: neighbors.append((loc[0]+1, loc[1])) if loc[1] != self.height-1: neighbors.append((loc[0], loc[1]+1)) if loc[0] != 0: neighbors.append((loc[0]-1, loc[1])) return neighbors - def test_visible(self, loc): + def _test_visible(self, loc): corners = [ Point(loc[0], loc[1]),Point(loc[0]+1, loc[1]),Point(loc[0], loc[1]+1),Point(loc[0]+1, loc[1]+1) ] center = Point(self.player_loc[0]+0.5, self.player_loc[1]+0.5) for p in corners: @@ -131,6 +136,8 @@ def update_visibility(self): for x in range(0, self.width): if self.visibility[y][x] == -1: self.visibility[y][x] = False + def delay(self): + time.sleep(MIN_DELAY) def serialize(self): grid = [] for y in range(0, self.height): @@ -142,19 +149,3 @@ def serialize(self): row.append(UNKNOWN) grid.append(row) return json.dumps(grid) - -MAX_SEC = 60 - -m = Map(5, 5, 0) -start_time = time.time(); -game_over = False -while not game_over: - m.update_visibility() - send_string(m.serialize()) - try: - move = get_move(MAX_SEC + start_time - time.time()) - game_over = m.make_move(move) - except Exception: - print(-1) - sys.exit(0) -print(time.time() - start_time) From 46af795331dc7747d0f24f4914f4294372c54aaf Mon Sep 17 00:00:00 2001 From: Sydriax Date: Mon, 5 Sep 2016 14:38:11 -0400 Subject: [PATCH 5/8] updates! --- problems/maze/env/main.py | 3 ++- problems/maze/starter/run.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/problems/maze/env/main.py b/problems/maze/env/main.py index de6fe4d..ae7a220 100644 --- a/problems/maze/env/main.py +++ b/problems/maze/env/main.py @@ -16,8 +16,9 @@ def start(): def move(key, move): result = games[key].make_move(move) if result != 0: + send_string("Result: " + ("SUCCESS" if result == 1 else "FAILURE") + " in " + str(time.time()-games[key].start_time) + " seconds.") del games[key] - return result + return time.time()-games[key].start_time if result == 1 else -1 # -1 indicates failure; any other value is the time it took them to complete the maze. games[key].update_visibility() games[key].delay() send_string(games[key].serialize()) # Josh, I'm assuming that 'send_string' exists, because I have no idea how you want it to be written. diff --git a/problems/maze/starter/run.py b/problems/maze/starter/run.py index e69de29..a02118a 100644 --- a/problems/maze/starter/run.py +++ b/problems/maze/starter/run.py @@ -0,0 +1,12 @@ +import subprocess, sys + +connect_to_server(); # Assumed to exist. + +proc = subprocess.Popen(sys.argv[1], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True) + +while True: + s = get_string() # Assume to exist. + if s.split(' ')[0] == "Result:": + print(s) + break + proc.communicate(s) From 5b3ba9f89cb0b646432440a243200df1663f83b4 Mon Sep 17 00:00:00 2001 From: Sydriax Date: Mon, 5 Sep 2016 17:18:51 -0400 Subject: [PATCH 6/8] Added precompiled headers to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4bfbc46..627f19e 100755 --- a/.gitignore +++ b/.gitignore @@ -271,3 +271,5 @@ nohub.out gitpull.php nycsl.ini + +*.gch From 0217d60b3a01727573f4b388a6ac68d1da017c8d Mon Sep 17 00:00:00 2001 From: Sydriax Date: Mon, 5 Sep 2016 17:19:27 -0400 Subject: [PATCH 7/8] Some renames, but primarily wrote c++ header --- .../maze/starter/c++11/{Maze.cpp => main.cpp} | 0 problems/maze/starter/c++11/maze.hpp | 53 +++++++++++++++++++ .../{c++11/Networking.hpp => java7/main.java} | 0 .../starter/java7/{Maze.java => maze.java} | 0 problems/maze/starter/python3/Networking.py | 0 .../Networking.java => python3/main.py} | 0 .../maze/starter/python3/{Maze.py => maze.py} | 0 7 files changed, 53 insertions(+) rename problems/maze/starter/c++11/{Maze.cpp => main.cpp} (100%) create mode 100644 problems/maze/starter/c++11/maze.hpp rename problems/maze/starter/{c++11/Networking.hpp => java7/main.java} (100%) rename problems/maze/starter/java7/{Maze.java => maze.java} (100%) delete mode 100644 problems/maze/starter/python3/Networking.py rename problems/maze/starter/{java7/Networking.java => python3/main.py} (100%) rename problems/maze/starter/python3/{Maze.py => maze.py} (100%) diff --git a/problems/maze/starter/c++11/Maze.cpp b/problems/maze/starter/c++11/main.cpp similarity index 100% rename from problems/maze/starter/c++11/Maze.cpp rename to problems/maze/starter/c++11/main.cpp diff --git a/problems/maze/starter/c++11/maze.hpp b/problems/maze/starter/c++11/maze.hpp new file mode 100644 index 0000000..baf4be6 --- /dev/null +++ b/problems/maze/starter/c++11/maze.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include +#include +#include + +#define NORTH 0 +#define EAST 1 +#define SOUTH 2 +#define WEST 3 + +#define UNKNOWN 0 +#define EMPTY 1 +#define WALL 2 +#define GLASS 3 +#define GOAL 4 +#define PLAYER 5 + +typedef std::vector< std::vector > Maze; +static std::istream & operator>>(std::istream & i, Maze & m) { + std::string str; + char c; + do { + c = i.get(); + if(!isspace(c)) throw 0; + } while(c != '['); + int sq_br_cntr = 1, vrt_cntr = 0; + do { + c = i.get(); + if(c == '[') { + sq_br_cntr++; + vrt_cntr++; + str.push_back(' '); + } + else if(c == ']') { + sq_br_cntr--; + str.push_back(' '); + } + else if(c == ',') str.push_back(' '); + else if(isdigit(c)) str.push_back(c); + else if(!isspace(c)) throw 0; + } while(sq_br_cntr > 0); + m.resize(vrt_cntr); + int wdth = std::count(str.begin(), str.end(), ' ') / vrt_cntr; + std::stringstream strstrm(str); + for(auto a = m.begin(); a != m.end(); a++) { + a->resize(wdth); + for(auto b = a->begin(); b != a->end(); b++) strstrm >> *b; + } + return i; +} diff --git a/problems/maze/starter/c++11/Networking.hpp b/problems/maze/starter/java7/main.java similarity index 100% rename from problems/maze/starter/c++11/Networking.hpp rename to problems/maze/starter/java7/main.java diff --git a/problems/maze/starter/java7/Maze.java b/problems/maze/starter/java7/maze.java similarity index 100% rename from problems/maze/starter/java7/Maze.java rename to problems/maze/starter/java7/maze.java diff --git a/problems/maze/starter/python3/Networking.py b/problems/maze/starter/python3/Networking.py deleted file mode 100644 index e69de29..0000000 diff --git a/problems/maze/starter/java7/Networking.java b/problems/maze/starter/python3/main.py similarity index 100% rename from problems/maze/starter/java7/Networking.java rename to problems/maze/starter/python3/main.py diff --git a/problems/maze/starter/python3/Maze.py b/problems/maze/starter/python3/maze.py similarity index 100% rename from problems/maze/starter/python3/Maze.py rename to problems/maze/starter/python3/maze.py From d393c389527ad234474c98bf55ca9ca53bfd6885 Mon Sep 17 00:00:00 2001 From: Sydriax Date: Mon, 5 Sep 2016 17:46:36 -0400 Subject: [PATCH 8/8] switched from preproc to consts --- problems/maze/starter/c++11/main.cpp | 11 +++++++++++ problems/maze/starter/c++11/maze.hpp | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/problems/maze/starter/c++11/main.cpp b/problems/maze/starter/c++11/main.cpp index e69de29..cbcff09 100644 --- a/problems/maze/starter/c++11/main.cpp +++ b/problems/maze/starter/c++11/main.cpp @@ -0,0 +1,11 @@ +#include //Needed to get the time so that we can seed our random number generator. +#include "maze.hpp" //Contains the core maze utils, such as consts, typedefs, and the >> overload. + +int main() { + srand(time(NULL)); //Seeds random number generator with the time so that output is always different. + Maze m; + while(true) { + std::cin >> m; //Gets the present maze. + std::cout << rand() % 4; //Sends a random direction back. Directions are ints as defined in maze.hpp + } +} diff --git a/problems/maze/starter/c++11/maze.hpp b/problems/maze/starter/c++11/maze.hpp index baf4be6..4cdd919 100644 --- a/problems/maze/starter/c++11/maze.hpp +++ b/problems/maze/starter/c++11/maze.hpp @@ -6,17 +6,17 @@ #include #include -#define NORTH 0 -#define EAST 1 -#define SOUTH 2 -#define WEST 3 +const int NORTH = 0; +const int EAST = 1; +const int SOUTH = 2; +const int WEST = 3; -#define UNKNOWN 0 -#define EMPTY 1 -#define WALL 2 -#define GLASS 3 -#define GOAL 4 -#define PLAYER 5 +const int UNKNOWN = 0; +const int EMPTY = 1; +const int WALL = 2; +const int GLASS = 3; +const int GOAL = 4; +const int PLAYER = 5; typedef std::vector< std::vector > Maze; static std::istream & operator>>(std::istream & i, Maze & m) {