reversi.htm

戻る

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML LANG="ja">

<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=Shift_JIS">
<TITLE>オセロ</TITLE>
</HEAD>

<BODY BGCOLOR="#CCFFFF">
<BR><BR>
<CENTER>

<!-- 盤 -->
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD WIDTH=14 HEIGHT=22></TD><TD WIDTH=1></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>a</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>b</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>c</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>d</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>e</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>f</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>g</B></FONT></TD>
<TD ALIGN=CENTER><FONT SiZE=4><B>h</B></FONT></TD>
</TR>
<TR><TD HEIGHT=1></TD><TD COLSPAN=9 HEIGHT=1><IMG SRC="images/board_t.gif" WIDTH=297 HEIGHT=1></TD></TR>
<TR>
<TD><FONT SiZE=4><B>1</B></FONT></TD>
<TD ROWSPAN=8 WIDTH=1><IMG SRC="images/board_l.gif" WIDTH=1 HEIGHT=296></TD>
<TD><A HREF="javascript:clicked(0,0)" onFocus="window.focus()"><IMG NAME="square00" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,0)" onFocus="window.focus()"><IMG NAME="square10" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,0)" onFocus="window.focus()"><IMG NAME="square20" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,0)" onFocus="window.focus()"><IMG NAME="square30" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,0)" onFocus="window.focus()"><IMG NAME="square40" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,0)" onFocus="window.focus()"><IMG NAME="square50" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,0)" onFocus="window.focus()"><IMG NAME="square60" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,0)" onFocus="window.focus()"><IMG NAME="square70" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>2</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,1)" onFocus="window.focus()"><IMG NAME="square01" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,1)" onFocus="window.focus()"><IMG NAME="square11" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,1)" onFocus="window.focus()"><IMG NAME="square21" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,1)" onFocus="window.focus()"><IMG NAME="square31" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,1)" onFocus="window.focus()"><IMG NAME="square41" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,1)" onFocus="window.focus()"><IMG NAME="square51" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,1)" onFocus="window.focus()"><IMG NAME="square61" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,1)" onFocus="window.focus()"><IMG NAME="square71" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>3</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,2)" onFocus="window.focus()"><IMG NAME="square02" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,2)" onFocus="window.focus()"><IMG NAME="square12" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,2)" onFocus="window.focus()"><IMG NAME="square22" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,2)" onFocus="window.focus()"><IMG NAME="square32" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,2)" onFocus="window.focus()"><IMG NAME="square42" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,2)" onFocus="window.focus()"><IMG NAME="square52" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,2)" onFocus="window.focus()"><IMG NAME="square62" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,2)" onFocus="window.focus()"><IMG NAME="square72" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>4</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,3)" onFocus="window.focus()"><IMG NAME="square03" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,3)" onFocus="window.focus()"><IMG NAME="square13" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,3)" onFocus="window.focus()"><IMG NAME="square23" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,3)" onFocus="window.focus()"><IMG NAME="square33" SRC="images/disc_w.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,3)" onFocus="window.focus()"><IMG NAME="square43" SRC="images/disc_b.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,3)" onFocus="window.focus()"><IMG NAME="square53" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,3)" onFocus="window.focus()"><IMG NAME="square63" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,3)" onFocus="window.focus()"><IMG NAME="square73" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>5</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,4)" onFocus="window.focus()"><IMG NAME="square04" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,4)" onFocus="window.focus()"><IMG NAME="square14" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,4)" onFocus="window.focus()"><IMG NAME="square24" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,4)" onFocus="window.focus()"><IMG NAME="square34" SRC="images/disc_b.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,4)" onFocus="window.focus()"><IMG NAME="square44" SRC="images/disc_w.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,4)" onFocus="window.focus()"><IMG NAME="square54" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,4)" onFocus="window.focus()"><IMG NAME="square64" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,4)" onFocus="window.focus()"><IMG NAME="square74" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>6</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,5)" onFocus="window.focus()"><IMG NAME="square05" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,5)" onFocus="window.focus()"><IMG NAME="square15" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,5)" onFocus="window.focus()"><IMG NAME="square25" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,5)" onFocus="window.focus()"><IMG NAME="square35" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,5)" onFocus="window.focus()"><IMG NAME="square45" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,5)" onFocus="window.focus()"><IMG NAME="square55" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,5)" onFocus="window.focus()"><IMG NAME="square65" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,5)" onFocus="window.focus()"><IMG NAME="square75" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>7</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,6)" onFocus="window.focus()"><IMG NAME="square06" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,6)" onFocus="window.focus()"><IMG NAME="square16" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,6)" onFocus="window.focus()"><IMG NAME="square26" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,6)" onFocus="window.focus()"><IMG NAME="square36" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,6)" onFocus="window.focus()"><IMG NAME="square46" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,6)" onFocus="window.focus()"><IMG NAME="square56" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,6)" onFocus="window.focus()"><IMG NAME="square66" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,6)" onFocus="window.focus()"><IMG NAME="square76" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
<TR>
<TD><FONT SiZE=4><B>8</B></FONT></TD>
<TD><A HREF="javascript:clicked(0,7)" onFocus="window.focus()"><IMG NAME="square07" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(1,7)" onFocus="window.focus()"><IMG NAME="square17" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(2,7)" onFocus="window.focus()"><IMG NAME="square27" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(3,7)" onFocus="window.focus()"><IMG NAME="square37" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(4,7)" onFocus="window.focus()"><IMG NAME="square47" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(5,7)" onFocus="window.focus()"><IMG NAME="square57" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(6,7)" onFocus="window.focus()"><IMG NAME="square67" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
<TD><A HREF="javascript:clicked(7,7)" onFocus="window.focus()"><IMG NAME="square77" SRC="images/board.gif" WIDTH=37 HEIGHT=37 BORDER=0></A></TD>
</TR>
</TABLE>

<BR><BR>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR="#336666">
<TR><TD COLSPAN=6 WIDTH=240 HEIGHT=35><SPAN ID="msg">
    <FONT COLOR="#000000" SIZE="+1">●</FONT><FONT COLOR="#FFFF33" SIZE="+1"> の手番</FONT>
    </SPAN></TD></TR>
<TR><TD WIDTH=40><BR></TD>
    <TD WIDTH=40 ALIGN=RIGHT><FONT COLOR="#000000" SIZE="+1">●</FONT></TD>
    <TD WIDTH=40 ALIGN=LEFT><FONT ID="b_dsc" COLOR="#FFFF33" SIZE="+1">2</FONT></TD>
    <TD WIDTH=40 ALIGN=RIGHT><FONT COLOR="#FFFFFF" SIZE="+1">●</FONT></TD>
    <TD WIDTH=40 ALIGN=LEFT><FONT ID="w_dsc" COLOR="#FFFF33" SIZE="+1">2</FONT></TD>
    <TD><BR></TD></TR>
</TABLE>

</CENTER>

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--

function clicked(x, y) {
  if(in_clicked)
    return;

  if(squares[x][y])  // すでに石がある
    return;

  if(!place(x, y, turn))  // 置けない
    return;

  in_clicked = true;

  put_msg("<FONT COLOR='#" + ((turn == 1) ? "000000" : "FFFFFF")
        + "' SIZE='+1'>●</FONT><FONT COLOR='#FFFF33' SIZE='+1'> "
        + "abcdefgh".charAt(x) + " " + String(y + 1) + "</FONT>");
  squares[x][y] = turn;
  document.images["square" + String(x) + String(y)].src = (turn == 1) ? img_b.src : img_w.src;
  discs_sum++;
  if(turn == 1) {  // 黒の手番
    b_discs++;
    document.getElementById("b_dsc").innerHTML = String(b_discs);
  }
  else {
    document.getElementById("w_dsc").innerHTML = String(discs_sum - b_discs);
  }
  g_x = x;
  g_y = y;
  g_dx = -2;
  g_dy = 1;
  g_cnt = 0;
  setTimeout("clicked2()", 500);
}

function clicked2() {
  // 相手の石を返す
  if(g_cnt) {
    g_x2 += g_dx;
    g_y2 += g_dy;
    squares[g_x2][g_y2] = turn;
    document.images["square" + String(g_x2) + String(g_y2)].src = (turn == 1) ? img_b.src : img_w.src;
    if(turn == 1)  // 黒の手番
      b_discs++;
    else
      b_discs--;
    document.getElementById("b_dsc").innerHTML = String(b_discs);
    document.getElementById("w_dsc").innerHTML = String(discs_sum - b_discs);
    g_cnt--;
    setTimeout("clicked2()", 100);
  }
  else {
    for(; ; ) {
      if(++g_dy < 2) {
        if(!g_dx && !g_dy)
          continue;
        g_x2 = g_x + g_dx;
        g_y2 = g_y + g_dy;
        if(g_x2 < 0 || g_x2 > 7 || g_y2 < 0 || g_y2 > 7)
          continue;
        if(squares[g_x2][g_y2] != 3 - turn)  // 空き or 自分の石
          continue;
        for(g_cnt = 1; ; g_cnt++) {
          g_x2 += g_dx;
          g_y2 += g_dy;
          if(g_x2 < 0 || g_x2 > 7 || g_y2 < 0 || g_y2 > 7)
            break;
          if(!squares[g_x2][g_y2])  // 空き
            break;
          if(squares[g_x2][g_y2] == turn) {  // 自分の石
            // 挟んだ
            g_x2 = g_x;
            g_y2 = g_y;
            clicked2();
            return;
          }
        }
        continue;
      }
      else {
        if(++g_dx < 2) {
          g_dy = -2;
          continue;
        }

        // 相手の番?
        // 置けるところがあるか?
        var f = 0;
        var x2, y2;
        for(x2 = 0; x2 < 8; x2++) {
          for(y2 = 0; y2 < 8; y2++) {
            if(!squares[x2][y2]) {  // 空き
              if(place(x2, y2, 3 - turn)) {  // 置ける
                turn = 3 - turn;  // 相手の番
                put_msg("<FONT COLOR='#" + ((turn == 1) ? "000000" : "FFFFFF")
                      + "' SIZE='+1'>●</FONT><FONT COLOR='#FFFF33' SIZE='+1'> の手番</FONT>");

                in_clicked = false;
                return;
              }
              if(place(x2, y2, turn))  // 自分は置ける
                f = 1;
            }
          }
        }
        if(f) {  // 自分は置ける
          // 相手はパス
          g_cnt = 6;
          pass();

          in_clicked = false;
          return;
        }

        // 終了
        put_msg(((b_discs * 2 == discs_sum)
                   ? "<FONT COLOR='#FFFF33' SIZE='+1'>引き分け!</FONT>"
                   : "<FONT COLOR='#" + ((b_discs > discs_sum - b_discs) ? "000000" : "FFFFFF")
                       + "' SIZE='+1'>●</FONT><FONT COLOR='#FFFF33' SIZE='+1'> の勝ち!</FONT>")
                  + "<A HREF='javascript:location.reload()' STYLE='text-decoration:none; position:relative; left:20px'>"
                  + "<SPAN STYLE='background-color:#CC3300; padding:2px 10px'>"
                  + "<FONT COLOR='#FFFF66'><B>もう一度遊ぶ</B></FONT></SPAN></A>");

        in_clicked = false;
        return;
      }
    }
  }
}

// パス
function pass() {
  if(g_cnt) {
    if(--g_cnt & 0x1) {
      put_msg("<FONT COLOR='#" + ((turn == 1) ? "FFFFFF" : "000000")
            + "' SIZE='+1'>●</FONT><FONT COLOR='#FFFF33' SIZE='+1'> はパス!</FONT>");
      setTimeout("pass()", 300);
    }
    else {
      put_msg("<BR>");
      setTimeout("pass()", 200);
    }
    return;
  }
  put_msg("<FONT COLOR='#" + ((turn == 1) ? "000000" : "FFFFFF")
        + "' SIZE='+1'>●</FONT><FONT COLOR='#FFFF33' SIZE='+1'> の手番</FONT>");
}

// 置ける?
function place(x, y, side) {
  // 回りのマスを調べる
  var dx, dy;
  for(dx = -1; dx < 2; dx++) {
    for(dy = -1; dy < 2; dy++) {
      if(dx || dy) {
        var x2 = x + dx;
        var y2 = y + dy;
        if(x2 < 0 || x2 > 7 || y2 < 0 || y2 > 7)
          continue;
        if(squares[x2][y2] != 3 - side)  // 空き or 自分の石
          continue;
        for(; ; ) {
          x2 += dx;
          y2 += dy;
          if(x2 < 0 || x2 > 7 || y2 < 0 || y2 > 7)
            break;
          if(!squares[x2][y2])  // 空き
            break;
          if(squares[x2][y2] == side)  // 自分の石
            return 1;  // 置ける
        }
      }
    }
  }
  return 0;
}

function put_msg(msg) {
  document.getElementById("msg").innerHTML = msg;
}

  squares = new Array();
  squares.length = 8;
  for(x = 0; x < 8; x++)
    squares[x] = [0, 0, 0, 0, 0, 0, 0, 0];
  squares[4][3] = squares[3][4] = 1;  // 黒
  squares[3][3] = squares[4][4] = 2;  // 白
  b_discs = 2;
  discs_sum = 4;
  img_b = new Image(37, 37);
  img_b.src = "images/disc_b.gif";
  img_w = new Image(37, 37);
  img_w.src = "images/disc_w.gif";
  turn = 1;  // 黒の番

  in_clicked = false;

//-->
</SCRIPT>

</BODY>

</HTML>