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

📄 stonestasher.java

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

// $Id: StoneStasher.java,v 1.3 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.ui.UpdatableBoard;
import ergo.util.Position;
import ergo.util.PositionVector;
// These three imported temporarily for StonePopup.
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.PopupMenu;
import java.awt.MenuItem;

// All clients of StoneStasher must call emit() when they wish to
// visify results of changes to array....
// also must use Game.setCurrentMove() whenever the active move
// changes.... 
// +++ The StoneStasher should probably manage the group array as
//     well as the stone array.  Essentially it should represent
//     (the current state of) a Go _board_, and the game should
//     represent the entire game.
// AMB -  Actually, I've gone away from this idea, and further 
//       reduced responsibilities so that StoneStasher may take
//       pride of place as level 3 of a Levelizable Bill Design...(ask wms!)
//       There seems to be too much interdependence in Ergo, which
//       is probably a Bad Thing. Lots of code where people
//       navigate long distances through Game, GameWindow, etc...
//       I'm trying in a small way to split off BoardCanvas as a start 
//       from the rest, ultimately with reference only to StoneStasher,
//       and another class, yet to be implemented, called something 
//       like GameStateInfo, or so.

// This should eventually communicate with BoardCanvas only through
// an interface...

// AMB Further thoughts: This class should be renamed 
//     VisibleGameState. The group array management should be
//     factored out of Game into InvisibleGameState....

public class StoneStasher { // stoneArray is now well and truly hidden....
  private static Position privp = new Position(0, 0);

  private UpdatableBoard updatable = null;
  private int[][] stoneArray;
  // tick is used to store a tick indicating whether or not
  // the given position needs to be redrawn.
  private int[][] tickArray;
  private boolean quietness;
  private boolean currentMoveChanged;
  private Move currentMove;
  private PositionVector dirties = new PositionVector();

  StoneStasher (int size) {
    if (size > 0) {
      stoneArray = new int[size][size];
      tickArray = new int[size][size];
      for (int i = 0; i < size; i++)
	for (int j = 0; j < size; j++) 
	  stoneArray[i][j] = Move.EMPTY;
    }
  }

  // Used by SGF reader to associate a window with a Game after loading.
  // Not at the moment.
  public void associateUpdatable (UpdatableBoard b) {
    updatable = b;
  }

  public void setQuiet (boolean quietness1) { quietness = quietness1; }

  public boolean getQuiet () { return quietness; }

  // Note that there has been a move made.  This will affect such
  // things as whether or not board decorations need to be redrawn.
  public void setCurrentMove (Move m) { 
    currentMoveChanged = true; 
    currentMove = m;
  }
  public Move getCurrentMove () {
    return currentMove;
  }

  private static int emitCount = 0;

  // Returns true if this emission causes move change.
  public boolean emit() {
    ++emitCount;
    if (!quietness && updatable != null && updatable.isReady()) {
      for (int i = dirties.size() - 1; i >= 0; --i) {
	Position p = dirties.elementAt(i);
	if (tickArray[p.row][p.column] < emitCount) {
	  updatable.reflect(p.row, p.column, stoneArray[p.row][p.column]);
	  tickArray[p.row][p.column] = emitCount;
	}
	dirties.removeElementAt(i);
      }
      if (currentMoveChanged)
	updatable.noteMove(currentMove);
      updatable.updateInternal();
      if (currentMoveChanged) {
	currentMoveChanged = false;
	return true;
      }
    }
    return false;
  }

  // This canonicalizes the stone to BLACK, WHITE, or EMPTY so that 
  // backup() etc will work in scoring mode, when empty positions
  // may be marked as belonging to white or black.  This should be
  // used by all but the scoring routines, which use readAnyStone().
  public int readStone (int row, int col) {
    int stone = stoneArray[row][col];
    switch (stone) {
    case Move.BLACK:
    case Move.WHITE:
      return stone;
    default:
      return Move.EMPTY;
    }
  }

  public int readAnyStone (int row, int col) {
    return stoneArray[row][col];
  }

  public void writeStone (int row, int col, int contents) {
    writeStone(row, col, contents, true);
  }

  // The scoring routines need to be able to write stones without
  // marking them as dirty.  Since they tend to traverse the entire
  // board each time, setting many empty positions to NONE and then
  // back to EMPTY, this avoids unnecessary redisplay.
  public void writeStone (int row, int col, int contents, boolean markAsDirty) {
    int prev = stoneArray[row][col];
    if (prev != contents) {
      stoneArray[row][col] = contents;
      if (markAsDirty)
	dirties.addElement(new Position(row, col));
    }
  }

  public void setKoPosition (Position p) {
    if (updatable != null)
      updatable.setKoPosition(p);
  }
}

⌨️ 快捷键说明

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