mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
merge冲突
This commit is contained in:
parent
10e207f5c2
commit
6953eaf4ca
1 changed files with 89 additions and 21 deletions
|
|
@ -3,11 +3,11 @@
|
|||
# @Desc : utils
|
||||
|
||||
from typing import Any, Union
|
||||
import os
|
||||
import json
|
||||
import openai
|
||||
from pathlib import Path
|
||||
import csv
|
||||
import os
|
||||
from ..prompts.run_gpt_prompts import get_poignancy_action, get_poignancy_chat
|
||||
|
||||
|
||||
|
|
@ -30,12 +30,12 @@ def write_json_file(json_file: str, data: list, encoding=None):
|
|||
|
||||
def read_csv_to_list(curr_file: str, header=False, strip_trail=True):
|
||||
"""
|
||||
Reads in a csv file to a list of list. If header is True, it returns a
|
||||
Reads in a csv file to a list of list. If header is True, it returns a
|
||||
tuple with (header row, all rows)
|
||||
ARGS:
|
||||
curr_file: path to the current csv file.
|
||||
RETURNS:
|
||||
List of list where the component lists are the rows of the file.
|
||||
curr_file: path to the current csv file.
|
||||
RETURNS:
|
||||
List of list where the component lists are the rows of the file.
|
||||
"""
|
||||
if not header:
|
||||
analysis_list = []
|
||||
|
|
@ -94,21 +94,89 @@ def extract_first_json_dict(data_str: str) -> Union[None, dict]:
|
|||
# If parsing fails, return None
|
||||
return None
|
||||
|
||||
def check_if_file_exists(curr_file):
|
||||
"""
|
||||
Checks if a file exists
|
||||
ARGS:
|
||||
curr_file: path to the current csv file.
|
||||
RETURNS:
|
||||
True if the file exists
|
||||
False if the file does not exist
|
||||
"""
|
||||
try:
|
||||
with open(curr_file) as f_analysis_file:
|
||||
pass
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def path_finder_v2(a, start, end, collision_block_char) -> list[int]:
|
||||
def make_step(m, k):
|
||||
for i in range(len(m)):
|
||||
for j in range(len(m[i])):
|
||||
if m[i][j] == k:
|
||||
if i > 0 and m[i - 1][j] == 0 and a[i - 1][j] == 0:
|
||||
m[i - 1][j] = k + 1
|
||||
if j > 0 and m[i][j - 1] == 0 and a[i][j - 1] == 0:
|
||||
m[i][j - 1] = k + 1
|
||||
if i < len(m) - 1 and m[i + 1][j] == 0 and a[i + 1][j] == 0:
|
||||
m[i + 1][j] = k + 1
|
||||
if j < len(m[i]) - 1 and m[i][j + 1] == 0 and a[i][j + 1] == 0:
|
||||
m[i][j + 1] = k + 1
|
||||
|
||||
new_maze = []
|
||||
for row in a:
|
||||
new_row = []
|
||||
for j in row:
|
||||
if j == collision_block_char:
|
||||
new_row += [1]
|
||||
else:
|
||||
new_row += [0]
|
||||
new_maze += [new_row]
|
||||
a = new_maze
|
||||
|
||||
m = []
|
||||
for i in range(len(a)):
|
||||
m.append([])
|
||||
for j in range(len(a[i])):
|
||||
m[-1].append(0)
|
||||
i, j = start
|
||||
m[i][j] = 1
|
||||
|
||||
k = 0
|
||||
except_handle = 150
|
||||
while m[end[0]][end[1]] == 0:
|
||||
k += 1
|
||||
make_step(m, k)
|
||||
|
||||
if except_handle == 0:
|
||||
break
|
||||
except_handle -= 1
|
||||
|
||||
i, j = end
|
||||
k = m[i][j]
|
||||
the_path = [(i, j)]
|
||||
while k > 1:
|
||||
if i > 0 and m[i - 1][j] == k - 1:
|
||||
i, j = i - 1, j
|
||||
the_path.append((i, j))
|
||||
k -= 1
|
||||
elif j > 0 and m[i][j - 1] == k - 1:
|
||||
i, j = i, j - 1
|
||||
the_path.append((i, j))
|
||||
k -= 1
|
||||
elif i < len(m) - 1 and m[i + 1][j] == k - 1:
|
||||
i, j = i + 1, j
|
||||
the_path.append((i, j))
|
||||
k -= 1
|
||||
elif j < len(m[i]) - 1 and m[i][j + 1] == k - 1:
|
||||
i, j = i, j + 1
|
||||
the_path.append((i, j))
|
||||
k -= 1
|
||||
|
||||
the_path.reverse()
|
||||
return the_path
|
||||
|
||||
|
||||
def path_finder(maze: "Maze", start: list[int], end: list[int], collision_block_char: str) -> list[int]:
|
||||
# EMERGENCY PATCH
|
||||
start = (start[1], start[0])
|
||||
end = (end[1], end[0])
|
||||
# END EMERGENCY PATCH
|
||||
|
||||
path = path_finder_v2(maze, start, end, collision_block_char)
|
||||
|
||||
new_path = []
|
||||
for i in path:
|
||||
new_path += [(i[1], i[0])]
|
||||
path = new_path
|
||||
|
||||
return path
|
||||
|
||||
def create_folder_if_not_there(curr_path):
|
||||
"""
|
||||
|
|
@ -151,4 +219,4 @@ def find_filenames(path_to_dir, suffix=".csv"):
|
|||
"""
|
||||
filenames = os.listdir(path_to_dir)
|
||||
return [path_to_dir + "/" + filename
|
||||
for filename in filenames if filename.endswith(suffix)]
|
||||
for filename in filenames if filename.endswith(suffix)]
|
||||
Loading…
Add table
Add a link
Reference in a new issue