Ejemplo n.º 1
0
def run_game():
    snake_coords = [(1, 2), (1, 1)]
    apple = get_apple_coord(snake_coords)
    score = 0

    canvas.draw_bg()
    canvas.draw_grid()
    canvas.draw_cell_line(snake_coords, canvas.COLOR.DARK_GRAY.value,
                          canvas.COLOR.DARK_GREEN.value)
    canvas.draw_cell(apple, canvas.COLOR.RED.value)
    canvas.update()

    while True:
        n_coord = next_coord(snake_coords, apple)
        if not n_coord:
            print("Game Over! STUCK")
            return

        score += move(snake_coords, n_coord, apple, draw=True)

        if not valid_coord(snake_coords[0], snake_coords[1:]):
            print("Game Over!")
            valid_coord(snake_coords[0], snake_coords[1:])
            return
        if len(snake_coords) == TOTAL:
            print("Game KO!")
            canvas.draw_grid()
            return
        if tools.cell_equal(n_coord, apple):
            apple = get_apple_coord(snake_coords)

        canvas.draw_cell(apple, canvas.COLOR.RED.value)
        canvas.draw_grid()
Ejemplo n.º 2
0
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from search.bfs import bfs

from graph import canvas

if __name__ == "__main__":
    canvas.init("BFS")
    canvas.draw_bg()
    canvas.draw_grid()

    start = (6, 5)
    end = (12, 10)
    obstacles = []
    for x in range(4, 10):
        obstacles.append((x, 3))
    for x in range(4, 20):
        obstacles.append((x, 12))
    for y in range(2, 14):
        obstacles.append((10, y))
    for y in range(2, 16):
        obstacles.append((17, y))

    canvas.draw_cell(start, canvas.COLOR.GREEN.value)