einfaches timen vom brute-force

This commit is contained in:
Alfred Baumann
2026-06-09 11:16:31 +02:00
parent 21b9ce7ad7
commit 52142da3f3
2 changed files with 24 additions and 8 deletions

View File

@@ -15,16 +15,8 @@ class BruteForceSolver:
self.game.set_direction(x, y, Direction.UP)
def solve(self) -> Generator[None]:
attempts = 0
required = 4 ** (self.game.width * self.game.height)
while not self.game.solved():
yield
attempts += 1
print(
f"{attempts:0>{len(str(required))}}/{required} ({attempts / required * 100}%) ",
end="\r",
)
self.game.turn_cw(0, 0)
for prev, curr in pairwise(
chain(

24
src/algorithms/profile.py Normal file
View File

@@ -0,0 +1,24 @@
import time
from multiprocessing import Pool
from src.algorithms.bruteforce import BruteForceSolver
from src.net import NetGame
def test_run() -> float:
game = NetGame(3, 3)
solver = BruteForceSolver(game)
a = time.perf_counter()
for _ in solver.solve():
pass
b = time.perf_counter()
return b - a
if __name__ == "__main__":
total = 0
with Pool() as p:
processes = [p.apply_async(test_run) for _ in range(100)]
for proc in processes:
total += proc.get()
print(total)