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

📄 stonemove.java

📁 ErGo是一个很早的Java通用围棋服务器(IGS/NNGS)客户端程序。有全部源码和文档
💻 JAVA
字号:
package ergo.logic;

// $Id: StoneMove.java,v 1.2 1999/08/13 01:17:49 sigue Exp $

/*
 *  Copyright (C) 1999  Carl L. Gay and Antranig M. Basman.
 *  See the file copyright.txt, distributed with this software,
 *  for further information.
 */

import ergo.util.*;
import java.io.PrintWriter;

/****************************************************
 * A StoneMove is the standard move where a single
 * stone is placed on the board.
 */
public class StoneMove extends Move {
  protected PositionVector placedPositions = new PositionVector(1, 0);
  protected Position position;		// board position (row, col)

  // any groups that were captured on this move.
  protected SimpleGroupVector capturedGroups;


  public StoneMove (Move parent, int timeleft, int num, int color, boolean isVar,
		    Position pos) {
    super(parent, timeleft, num, color, isVar);
    position = pos;
    placedPositions.addElement(position);
  }

  public StoneMove (Move parent, int timeleft, int num, int color, boolean isVar,
	     int row, int col) {
    super(parent, timeleft, num, color, isVar);
    position = new Position(row, col);
    placedPositions.addElement(position);
  }

  public void reseatforShadow(Position pos, int c, Move mom, int number1) {
    position = pos; color = c; parent = mom; moveNumber = number1;
  }

  public Position position () {
    return position;
  }

  public PositionVector placedPositions(int size) {
    return placedPositions;
  }

  public int numberOfStones () {
    return 1;
  }

  public SimpleGroupVector capturedGroups() {
    return capturedGroups;
  }

  public String toString () {
    return position.toString();
  }

  public boolean equals (Move m) {
    return (m instanceof StoneMove
	    && position.equals(((StoneMove) m).position()));
  }

  public void writeSGF (PrintWriter out, Game game, int n) {
    if (!(parent instanceof RootMove))
      out.print(";");
    out.print(((color == BLACK) ? "B" : "W") + position.asSGF(game.size()));
    // +++ Timing isn't implemented for local games (yet?).
    if (game.isNetGame())
      writeTimeLeft(out);
    super.writeSGF(out, game, n);
  }

  public boolean occupiesPosition (Position pos) {
    return position.equals(pos);
  }

  public SimpleGroupVector newGroups (Game game) {
    SimpleGroupVector groups = new SimpleGroupVector(1);
    groups.addElement(game.composeGroups(game.groupsAbutting(position, color),
					 color, position));
    return groups;
  }


  // Determines whether or not placing a stone of the given color at
  // the given position would be a legal move.  If the "fast"
  // parameter is true, only the quickest check is done to see if the
  // move is legal.  Else the groups captured by this move and the
  // group created by this move, or the error message for this move
  // are stored in the above globals.  I expect that the cursor
  // "shadow stones" code will pass fast = true.
  public boolean isLegal (Game game, boolean fast, ILMV result) {
    int row = position.row;
    int col = position.column;
    if (!super.isLegal(game, fast, result))
      return false;
    else if (game.stoneAt(row, col) != Move.EMPTY) {
      result.failureReason = "Position is occupied.";
      return false;
    }
    else if (game.koPosition() != null
	     && position.equals(game.koPosition())) {
      result.failureReason = "Position is ko.";
      return false;
    }
    else if (fast && game.numberOfLiberties(position) > 0)
      // The caller just wants a quick check.  Most of the time this
      // check will prevent the more expensive checks below.
      return true;
    else {
      boolean legal = false;
      // Check to see if any of the opponent's groups that abut
      // this position would be captured.  If so it's a legal move.
      // Store the groups that would be captured in result.capturedGroups.
      result.opponentGroups
	= game.groupsAbutting(position, Move.nextColor(color));
      if (result.opponentGroups != null) {
	for (int i = 0; i < result.opponentGroups.size(); i++) {
	  SimpleGroup g = result.opponentGroups.elementAt(i);
	  if (g.numberOfLiberties() == 1) {
	    if (fast)
	      return true;	// short circuit further testing
	    else {
	      if (legal == false) // this is the first group captured.
		capturedGroups = new SimpleGroupVector(1, 2);
	      capturedGroups.addElement(g);
	      legal = true;
	    }
	  }
	}
      }
      // Check to see if the group that this move would be added to
      // has any liberties (after adding pos).  If so, it's legal.
      result.newGroups = newGroups(game);
      if (legal || (result.newGroups.elementAt(0).numberOfLiberties() > 0))
	return true;
      else {
	result.failureReason = "Play into death";
	return false;
      }
    }
  }

}  // end class StoneMove

⌨️ 快捷键说明

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