| | 1975 | |
| | 1976 | return gtp_finish_response(); |
| | 1977 | } |
| | 1978 | |
| | 1979 | |
| | 1980 | /* Function: Analyze a semeai |
| | 1981 | * Arguments: dragona, dragonb |
| | 1982 | * Fails: invalid vertices, empty vertices |
| | 1983 | * Returns: Semeai status (if play) followed by move to play. |
| | 1984 | * 0=Loser, 1=Winner, 2=Seki, 3=Unknown, 4=Ko |
| | 1985 | */ |
| | 1986 | static int |
| | 1987 | gtp_solve_semeaiS(char *s) |
| | 1988 | { |
| | 1989 | int i, j; |
| | 1990 | int k; |
| | 1991 | int dragona, dragonb; |
| | 1992 | int resulta, resultb, move, result_certain; |
| | 1993 | int second_resulta, second_resultb, second_move; |
| | 1994 | int result; |
| | 1995 | |
| | 1996 | k = gtp_decode_coord(s, &i, &j); |
| | 1997 | |
| | 1998 | if (k == 0) |
| | 1999 | return gtp_failure("invalid coordinate"); |
| | 2000 | dragona = POS(i, j); |
| | 2001 | if (BOARD(i, j) == EMPTY) |
| | 2002 | return gtp_failure("vertex must not be empty"); |
| | 2003 | |
| | 2004 | if (!gtp_decode_coord(s+k, &i, &j)) |
| | 2005 | return gtp_failure("invalid coordinate"); |
| | 2006 | dragonb = POS(i, j); |
| | 2007 | if (BOARD(i, j) == EMPTY) |
| | 2008 | return gtp_failure("vertex must not be empty"); |
| | 2009 | |
| | 2010 | silent_examine_position(EXAMINE_DRAGONS_WITHOUT_OWL); |
| | 2011 | /* to get the variations into the sgf file, clear the reading cache */ |
| | 2012 | if (sgf_dumptree) |
| | 2013 | reading_cache_clear(); |
| | 2014 | |
| | 2015 | if (worm[dragona].invincible) { |
| | 2016 | int attack_code = owl_attack(dragonb, &move, &result_certain, NULL); |
| | 2017 | if (attack_code == 0) { |
| | 2018 | result = 2; |
| | 2019 | move = PASS_MOVE; |
| | 2020 | } |
| | 2021 | else if (attack_code == WIN) { |
| | 2022 | result = 1; |
| | 2023 | if (owl_defend(dragonb, &second_move, &result_certain, NULL) == 0) |
| | 2024 | move = PASS_MOVE; |
| | 2025 | } |
| | 2026 | else |
| | 2027 | result = 4; |
| | 2028 | } |
| | 2029 | else if (worm[dragonb].invincible) { |
| | 2030 | int defense_code = owl_defend(dragona, &move, &result_certain, NULL); |
| | 2031 | if (defense_code == 0) { |
| | 2032 | result = 0; |
| | 2033 | move = PASS_MOVE; |
| | 2034 | } |
| | 2035 | else if (defense_code == WIN) { |
| | 2036 | result = 2; |
| | 2037 | if (owl_attack(dragona, &second_move, &result_certain, NULL) == 0) |
| | 2038 | move = PASS_MOVE; |
| | 2039 | } |
| | 2040 | else |
| | 2041 | result = 4; |
| | 2042 | } |
| | 2043 | else { |
| | 2044 | owl_analyze_semeai(dragona, dragonb, &resulta, &resultb, &move, 1, |
| | 2045 | &result_certain); |
| | 2046 | owl_analyze_semeai(dragonb, dragona, &second_resulta, &second_resultb, |
| | 2047 | &second_move, 1, &result_certain); |
| | 2048 | |
| | 2049 | if (resulta == 0 && resultb == 0) { |
| | 2050 | result = 0; |
| | 2051 | move = PASS_MOVE; |
| | 2052 | } |
| | 2053 | else if (resulta == WIN && resultb == WIN) { |
| | 2054 | result = 1; |
| | 2055 | if (second_resulta == 0 && second_resultb == 0) |
| | 2056 | move = PASS_MOVE; |
| | 2057 | } |
| | 2058 | else if (resulta == WIN && resultb == 0) { |
| | 2059 | result = 2; |
| | 2060 | if (second_resulta == WIN && second_resultb == 0) |
| | 2061 | move = PASS_MOVE; |
| | 2062 | } |
| | 2063 | else |
| | 2064 | result = 4; |
| | 2065 | } |
| | 2066 | |
| | 2067 | gtp_start_response(GTP_SUCCESS); |
| | 2068 | gtp_mprintf("%d %m", result, I(move), J(move)); |