1*21214Sdist /* 2*21214Sdist * Copyright (c) 1980 Regents of the University of California. 3*21214Sdist * All rights reserved. The Berkeley software License Agreement 4*21214Sdist * specifies the terms and conditions for redistribution. 5*21214Sdist */ 66763Srrh 7*21214Sdist #ifndef lint 8*21214Sdist static char sccsid[] = "@(#)odds.c 5.1 (Berkeley) 05/29/85"; 9*21214Sdist #endif not lint 10*21214Sdist 116763Srrh #include "back.h" 126763Srrh 136763Srrh odds (r1,r2,val) 146763Srrh register int r1; 156763Srrh int r2, val; 166763Srrh { 176763Srrh register int i, j; 186763Srrh 196763Srrh if (r1 == 0) { 206763Srrh for (i = 0; i < 6; i++) 216763Srrh for (j = 0; j < 6; j++) 226763Srrh table[i][j] = 0; 236763Srrh return; 246763Srrh } else { 256763Srrh r1--; 266763Srrh if (r2-- == 0) 276763Srrh for (i = 0; i < 6; i++) { 286763Srrh table[i][r1] += val; 296763Srrh table[r1][i] += val; 306763Srrh } 316763Srrh else { 326763Srrh table[r2][r1] += val; 336763Srrh table[r1][r2] += val; 346763Srrh } 356763Srrh } 366763Srrh } 376763Srrh 386763Srrh count () { 396763Srrh register int i; 406763Srrh register int j; 416763Srrh register int total; 426763Srrh 436763Srrh total = 0; 446763Srrh for (i = 0; i < 6; i++) 456763Srrh for (j = 0; j < 6; j++) 466763Srrh total += table[i][j]; 476763Srrh return (total); 486763Srrh } 496763Srrh 506763Srrh canhit (i,c) 516763Srrh int i, c; 526763Srrh 536763Srrh { 546763Srrh register int j, k, b; 556763Srrh int a, d, diff, place, addon, menstuck; 566763Srrh 576763Srrh if (c == 0) 586763Srrh odds (0,0,0); 596763Srrh if (board[i] > 0) { 606763Srrh a = -1; 616763Srrh b = 25; 626763Srrh } else { 636763Srrh a = 1; 646763Srrh b = 0; 656763Srrh } 666763Srrh place = abs (25-b-i); 676763Srrh menstuck = abs (board[b]); 686763Srrh for (j = b; j != i; j += a) { 696763Srrh if (board[j]*a > 0) { 706763Srrh diff = abs(j-i); 716763Srrh addon = place+((board[j]*a > 2 || j == b)? 5: 0); 726763Srrh if ((j == b && menstuck == 1) && 736763Srrh (j != b && menstuck == 0)) 746763Srrh for (k = 1; k < diff; k++) 756763Srrh if (k < 7 && diff-k < 7 && 766763Srrh (board[i+a*k]*a >= 0 || 776763Srrh board[i+a*(diff-k)] >= 0)) 786763Srrh odds (k,diff-k,addon); 796763Srrh if ((j == b || menstuck < 2) && diff < 7) 806763Srrh odds (diff,0,addon); 816763Srrh } 826763Srrh if (j == b && menstuck > 1) 836763Srrh break; 846763Srrh } 856763Srrh return (count()); 866763Srrh } 87