⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rotated.htm

📁 电脑游戏中的人工智能制作的文章收集。 搞游戏设计和编程的人都可以参考一下
💻 HTM
📖 第 1 页 / 共 3 页
字号:
with<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> length of 
diagonal<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> */<BR><IMG 
height=3 src="Rotated.files/spacer.gif" width=15> for every diagonal state 
(0-(2^diag length)-1) <BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> 
{<BR><IMG height=3 src="Rotated.files/spacer.gif" width=30> decide which squares 
are occupied<BR><IMG height=3 src="Rotated.files/spacer.gif" width=30> note that 
not all squares are used in some diagonals<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> compute all moves on diagonal for this 
state up and left<BR><IMG height=3 src="Rotated.files/spacer.gif" width=30> 
compute all moves on diagonal for this state down and right<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> diag_A8H1_attacks[square][diag state] = 
attack_board;<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> 
}<BR>}<BR><BR>/*<BR>precompute H8/A1 bishop/queen moves<BR>*/<BR><BR>for every 
square (0-63) <BR>{<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> 
/*<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> number of diagonal 
"states" will vary with<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=15> length of diagonal<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=15> */<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> for every 
diagonal state (0-(2^diag length)-1) <BR><IMG height=3 
src="Rotated.files/spacer.gif" width=15> {<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> decide which squares are 
occupied<BR><IMG height=3 src="Rotated.files/spacer.gif" width=30> note that not 
all squares are used in some diagonals<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> compute all moves on diagonal for this 
state up and right<BR><IMG height=3 src="Rotated.files/spacer.gif" width=30> 
compute all moves on diagonal for this state down and left<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> diag_H8A1_attacks[square][diag state] = 
attack_board;<BR><IMG height=3 src="Rotated.files/spacer.gif" width=15> 
}<BR>}<BR></TT>
<P>Indexing diag_A8H1_attacks[64][256].</P>
<P>As before, the first index is the square the bishop sits on. The second index 
is the state of the diagonal running in the A8-&gt;H1 direction. </P>
<P>Just as before, we need to rotate the bitboard, perform a shift, and finally 
an AND to isolate the bits we're interested in.</P>
<P>To align the squares of the A8-&gt;H1 diagonal, we need to rotate the board 
45 degrees left. (This is a good time to grab a Coke and some NoDoze...) 
</P><TT>int r45L_map[64] = { <BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=100> 28,21,15,10,6,3,1,0,<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=100> 36,29,22,16,11,7,4,2,<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=100> 43,37,30,23,17,12,8,5,<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=100> 49,44,38,31,24,18,13,9,<BR><IMG 
height=3 src="Rotated.files/spacer.gif" width=100> 
54,50,45,39,32,25,19,14,<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=100> 58,55,51,46,40,33,26,20,<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=100> 61,59,56,52,47,41,34,27,<BR><IMG 
height=3 src="Rotated.files/spacer.gif" width=100> 63,62,60,57,53,48,42,35 
};<BR><BR>
<P>Notice how all the squares are ordered. They run sequentially from the upper 
left to the lower right. When the normal bitboard is mapped, the bits of the 
A8-H1 diagonal will be aligned (as will all diagonals running in that 
direction). </P>
<P>BitBoard Rotated45L = 0;<BR>for every square (0-63)<BR>{<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=15>if square is not empty<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> Rotated45L |= 
mask[r45L_map[square]];<BR>}<BR></P></TT>
<P>Now to shift the rotated board, but how many bits? </P>
<CENTER>
<TABLE border=1 cellPadding=0 cellSpacing=0 cols=9 width="25%">
  <CAPTION><B>Number of Bits to Shift</B></CAPTION>
  <TBODY>
  <TR>
    <TD></TD>
    <TD>
      <CENTER><B>H</B></CENTER></TD>
    <TD>
      <CENTER><B>G</B></CENTER></TD>
    <TD>
      <CENTER><B>F</B></CENTER></TD>
    <TD>
      <CENTER><B>E</B></CENTER></TD>
    <TD>
      <CENTER><B>D</B></CENTER></TD>
    <TD>
      <CENTER><B>C</B></CENTER></TD>
    <TD>
      <CENTER><B>B</B></CENTER></TD>
    <TD>
      <CENTER><B>A</B></CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>1</B></CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>58</CENTER></TD>
    <TD>
      <CENTER>61</CENTER></TD>
    <TD>
      <CENTER>63</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>2</B></CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>58</CENTER></TD>
    <TD>
      <CENTER>61</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>3</B></CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>58</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>4</B></CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>5</B></CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>6</B></CENTER></TD>
    <TD>
      <CENTER>3</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>7</B></CENTER></TD>
    <TD>
      <CENTER>1</CENTER></TD>
    <TD>
      <CENTER>3</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>8</B></CENTER></TD>
    <TD>
      <CENTER>0</CENTER></TD>
    <TD>
      <CENTER>1
      <CENTER></CENTER></CENTER></TD>
    <TD>
      <CENTER>3</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD></TR></TBODY></TABLE></CENTER><BR>
<P>Once the board is shifted, the final operation is the mask. The mask will 
vary with the length of the diagonal. <TT>Mask_Length = (2^diag_length)-1;</TT>. 
So if the length of the diagonal is 7 squares, the mask would equal 127. If the 
length of the diagonal was one square, the mask would equal 1. While it is 
possible to use this formula during exectution, it is probably faster to use a 
look up table. </P><BR>
<P>Indexing diag_H8A1_attacks[64][256].</P>
<P>To align the squares of the H8-&gt;A1 diagonal, we need to rotate the board 
45 degrees right. (Need another Coke? :-) ) </P><TT>int r45R_map[64] = { 
<BR><IMG height=3 src="Rotated.files/spacer.gif" width=100> 
0,1,3,6,10,15,21,28,<BR><IMG height=3 src="Rotated.files/spacer.gif" width=100> 
2,4,7,11,16,22,29,36,<BR><IMG height=3 src="Rotated.files/spacer.gif" width=100> 
5,8,12,17,23,30,37,43,<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=100> 9,13,18,24,31,38,44,49,<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=100> 14,19,25,32,39,45,50,54,<BR><IMG 
height=3 src="Rotated.files/spacer.gif" width=100> 
20,26,33,40,46,51,55,58,<BR><IMG height=3 src="Rotated.files/spacer.gif" 
width=100> 27,34,41,47,52,56,59,61,<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=100> 35,42,48,53,57,60,62,63 
};<BR><BR></TT>
<P>Notice how all the squares are ordered. They run sequentially from the upper 
right to the lower left. When the normal bitboard is mapped, the bits of the 
H8-A1 diagonal will be aligned (as will all diagonals running in that 
direction). </P><TT>
<P>BitBoard Rotated45R = 0;<BR>for every square (0-63)<BR>{<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=15>if square is not empty<BR><IMG height=3 
src="Rotated.files/spacer.gif" width=30> Rotated45R |= 
mask[r45R_map[square]];<BR>}<BR></P></TT>
<P>The shift.</P>
<CENTER>
<TABLE border=1 cellPadding=0 cellSpacing=0 cols=9 width="25%">
  <CAPTION><B>Number of Bits to Shift</B></CAPTION>
  <TBODY>
  <TR>
    <TD></TD>
    <TD>
      <CENTER><B>H</B></CENTER></TD>
    <TD>
      <CENTER><B>G</B></CENTER></TD>
    <TD>
      <CENTER><B>F</B></CENTER></TD>
    <TD>
      <CENTER><B>E</B></CENTER></TD>
    <TD>
      <CENTER><B>D</B></CENTER></TD>
    <TD>
      <CENTER><B>C</B></CENTER></TD>
    <TD>
      <CENTER><B>B</B></CENTER></TD>
    <TD>
      <CENTER><B>A</B></CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>1</B></CENTER></TD>
    <TD>
      <CENTER>63</CENTER></TD>
    <TD>
      <CENTER>61</CENTER></TD>
    <TD>
      <CENTER>58</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>2</B></CENTER></TD>
    <TD>
      <CENTER>61</CENTER></TD>
    <TD>
      <CENTER>58</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>3</B></CENTER></TD>
    <TD>
      <CENTER>58</CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>4</B></CENTER></TD>
    <TD>
      <CENTER>54</CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>5</B></CENTER></TD>
    <TD>
      <CENTER>49</CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>6</B></CENTER></TD>
    <TD>
      <CENTER>43</CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>3</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>7</B></CENTER></TD>
    <TD>
      <CENTER>36</CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21</CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>3</CENTER></TD>
    <TD>
      <CENTER>1</CENTER></TD></TR>
  <TR>
    <TD>
      <CENTER><B>8</B></CENTER></TD>
    <TD>
      <CENTER>28</CENTER></TD>
    <TD>
      <CENTER>21
      <CENTER></CENTER></CENTER></TD>
    <TD>
      <CENTER>15</CENTER></TD>
    <TD>
      <CENTER>10</CENTER></TD>
    <TD>
      <CENTER>6</CENTER></TD>
    <TD>
      <CENTER>3</CENTER></TD>
    <TD>
      <CENTER>1</CENTER></TD>
    <TD>
      <CENTER>0</CENTER></TD></TR></TBODY></TABLE></CENTER>
<P>And finally mask it just like the previous diagonal.</P>
<P>The bishop attack board is the logical OR of both 
diagonals.<BR><TT>bishop_attack = diag_A8H1_attacks | diag_H8A1_attacks;</TT> 
</P>
<P>Lastly, the queen attack board is the logical OR of the rook attack board and 
the bishop attack board.<BR><TT>queen_attack = rook_attack | bishop_attack;</TT> 
</P>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -