bitmacs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* This file contains bitmap-manipulation routines for CHESS.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. This file is part of CHESS.
  4. CHESS is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the CHESS General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. CHESS, but only under the conditions described in the
  12. CHESS General Public License. A copy of this license is
  13. supposed to have been given to you along with CHESS so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. #include <stdio.h>
  18. #include "algdefs.h"
  19. #include "crucialdefs.h"
  20. #include "fixeddefs.h"
  21. #include "externmap.h"
  22. #include "bitmacs.h"
  23. int stacki[64];
  24. int stackip;
  25. extern unsigned int sqbits[];
  26. /*
  27. * count_bits -- takes a bitmap as an argument
  28. * returns a count of the number of bits that are set
  29. */
  30. count_bits(map)
  31. unsigned int map[2];
  32. {
  33. register i,j,count;
  34. count = 0;
  35. if (NOT_ZERO(map))
  36. for (i = 0; i < WPERM; i++)
  37. for (j = 0; j < BPERW; j++)
  38. if (sqbits[j] & map[i])
  39. count++;
  40. return(count);
  41. }
  42. /*
  43. * next_bit -- takes a bitmap as an argument
  44. * modifies the integer stack so that all the bits
  45. * turned on in that bitmap are stored on the stack.
  46. */
  47. next_bit(map)
  48. unsigned int map[2];
  49. {
  50. register i,j;
  51. stackip = -1;
  52. if (map[0] != 0 || map[1] != 0)
  53. {
  54. for (i = 0; i < WPERM; i++)
  55. for (j = 0; j < BPERW; j++)
  56. if (sqbits[j] & map[i])
  57. {
  58. stacki[++stackip] = j+(BPERW*i);
  59. /*
  60. printf("stacki element %d = %d\n",
  61. stackip,stacki[stackip]);
  62. */
  63. }
  64. }
  65. return(stackip);
  66. }
  67. translmap(color,map,amap)
  68. unsigned int map[NCOLORS][BPERW*WPERM][2];
  69. unsigned int amap[NCOLORS][BPERW*WPERM][2];
  70. {
  71. register i,j;
  72. for (i = A1; i <= H8; i++)
  73. BIT_ZERO(amap[color][i]);
  74. for (j = A1; j <= H8; j++)
  75. if (NOT_ZERO(map[color][j]))
  76. for (i = A1; i <= H8; i++)
  77. if (MEMBER(i,map[color][j]))
  78. BIT_MSET(j,i,color,amap);
  79. }