ref: 407c0b5bf4f186ea4fbd8cd381a3036010bfe621
parent: 0281fe456e9e2ef7c3f8829b139f453f3e0aa159
author: mkf <mkf@cloud9p.org>
date: Thu May 23 18:13:33 EDT 2024
engine: take an argument in findmin, use findmin in score1
--- a/engine.c
+++ b/engine.c
@@ -261,17 +261,14 @@
int
score1(Point p)
{
- int min = 999, next;
+ int min = 999;
if(p.x == 0 || p.x == SzX-1 || p.y == 0 || p.y == SzY-1)
return 1; /* we can always escape from the edges */
- for(int dir = NE; dir <= NW; dir++)
- {
- next = checknext(dir, p);
- if(next < min)
- min = next;
- }
+ if(findmin(p) < min)
+ min = findmin(p);
+
if(min == 999)
return 998;
return 1+min;
@@ -288,10 +285,9 @@
}
int
-findmin(void)
+findmin(Point p)
{
- int next, min = 1000;
- Point p = findglenda();
+ int next, min = 999;
for(int dir = NE; dir <= NW; dir++)
{
@@ -342,9 +338,9 @@
{
Point p = findglenda();
- if(findmin() > 100)
+ if(findmin(p) > 100)
state = Won;
- else if(p.x == 0 || p.x == SzX-1 || p.y == 0 || p.y == SzY-1)
+ if(p.x == 0 || p.x == SzX-1 || p.y == 0 || p.y == SzY-1)
state = Lost;
return state;
--- a/engine.h
+++ b/engine.h
@@ -77,7 +77,7 @@
void calc(void);
void nextglenda(void);
-int findmin(void);
+int findmin(Point p);
int checkstate(void);
void restart(void);