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

📄 gameresultmove.java

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

// $Id: GameResultMove.java,v 1.2 1999/08/13 01:17:48 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.*;
import ergo.util.*;
import java.io.PrintWriter;


// There should only be one instance of this class per game.
// Modelling the game result as a move greatly simplifies 
// decisions about when to display the result during browsing.
public final class GameResultMove extends Move {
  private int[][] result = null;
  private int[][] saved = null;

  public GameResultMove (Move parent, int[][] gresult) {
    // super(parent, timeleft, moveNumber, color, isVariation)
    super(parent, 0, parent.moveNumber() + 1,
	  Move.nextColor(parent.color()), false);
    result = gresult;
  }

  public int[][] result () { return result; }

  public void noteMovePlaced (StoneStasher ss) {
    if (saved == null)
      saved = new int[result.length][result[0].length];
    // copy board contents to "saved" and display contents of "result".
    Debug.println("GameResultMove.noteMovePlaced");
    for (int row = 0; row < result.length; row++) {
      for (int col = 0; col < result[0].length; col++) {
	saved[row][col] = ss.readAnyStone(row, col);
//	System.out.print(saved[row][col] + " ");
	ss.writeStone(row, col, result[row][col]);
      }
//      System.out.println();
    }
    ss.emit();
  }

  public void noteMoveUndone (StoneStasher ss) {
    // copy the saved board position back
    for (int row = 0; row < saved.length; row++) {
      for (int col = 0; col < saved[0].length; col++)
	ss.writeStone(row, col, saved[row][col]);
    }
    ss.emit();
  }

  // I don't think this will ever be called for GameResultMoves.
  public boolean isLegal (Game g, boolean fast, ILMV result) {
    return true;
  }

  // Write out the WhiteTerritory and BlackTerritory properties.
  // Note that when this move is the current move being displayed
  // that the contents of the result array have been swapped with
  // the contents of the StoneStasher array, so we have to be sure
  // to look in the right place.
  public void writeSGF (PrintWriter out, Game game, int n) {
    if (!(parent instanceof RootMove))
      out.print(";");
    if (result != null) {
      writeTerritory(out, Move.WHITETERRITORY, "WhiteTerritory", game);
      writeTerritory(out, Move.BLACKTERRITORY, "BlackTerritory", game);
    }
    super.writeSGF(out, game, SGF.nodesPerLine);
  }

  private void writeTerritory (PrintWriter out, int stoneType, String prop, Game game) {
    boolean displayed = game.getCurrentMove() == this;
    boolean anyWritten = false;
    int size = game.size();
    int nperline = 10;
    int n = 0;
    StoneStasher ss = game.ss;
    out.println();
    for (int row = 0; row < result.length; row++)
      for (int col = 0; col < result[0].length; col++) {
	int stone = displayed ? ss.readAnyStone(row, col) : result[row][col];
	if (stone == stoneType) {
	  if (!anyWritten) {
	    out.print(prop);
	    anyWritten = true;
	  }
	  out.print(Position.asSGF(size, row, col));
	  if ((n = (n + 1) % nperline) == 0)
	    out.println();
	}
      }
  }

  public String toString () { return "Final Result"; }
  public PositionVector placedPositions (int x) { return null; }
  public boolean equals (Move m) { return m == this; }
  public SimpleGroupVector capturedGroups () { return null; }
  public int numberOfStones () { return 0; }
  // Seems this should return true, but not going to change it right now...
  public boolean occupiesPosition (Position pos) { return false; }
}

⌨️ 快捷键说明

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