Java.lang.VerifyError

3 respostas
Polimorphism

Apareceu esse erro estranho... alguém me ajuda?

Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: (class: periid/Move, method: <init> signature: (II)V) Constructor must call super() or this()
at periid.Board$1.mouseReleased(Board.java:65)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

package periid;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;

public class ArtificialMover implements Mover{
    int level;
    ArtificialMover(int level){
        this.level = 0;
    }
    public int getMove(Board clone) {
        ArrayList<Move> moves = clone.getAllPossibleMoves();
        int bestMove = 0;
        double bestMoveValue = Double.NEGATIVE_INFINITY;
        int draws = 0;
        int n = moves.size();
        ArrayList<Integer> possibles = new ArrayList<Integer>();
        double values[] = new double[n];
        
        for(int a = 0 ; a < n ; a++){
            Board nextClone = clone.clone();
            nextClone.makeMove(moves.get(a));
            double value = evaluate(nextClone, level);
            values[a] = value;
            if(value > bestMoveValue){
                bestMove = a;
                draws = 1;
                possibles.clear();
                possibles.add(a);
            }
            else if(value == bestMoveValue){
                draws++;
                possibles.add(a);
            }
        }

        if(draws > 1){
            Random generator = new Random();
            double index = draws;
            for(int a = 0 ; a < draws ; a++){
                double chance = 1/index;
                double random = generator.nextDouble();
                if(chance > random){
                    return possibles.get(a);
                }
                else{
                    index = index - 1;
                }
            }
        }
        return bestMove;
    }
    double evaluate(Board x, int iterations){
        // UNDER CONSTRUCTION
        return 0.0;
    }
}

class Move{
    int number;
    int value;
    Move(int number, int value){
        this.number = number;
        this.value = value;
    }
}
package periid;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Board extends JPanel {

    final int X;
    final int Y;
    private Unit[][] squares;
    private boolean currentPlayer = false;
    Mover redMover, greenMover;

    Board() {
        redMover = null;
        greenMover = new ArtificialMover(0);
        X = 6;
        Y = 6;
        squares = new Unit[6][6];
        squares[0][0] = new UnitVeles(1, true, "green");
        squares[1][0] = new UnitSword(1, true, "green");
        squares[2][0] = new UnitSword(1, true, "green");
        squares[3][0] = new UnitVeles(1, true, "green");
        squares[4][0] = new UnitVeles(1, true, "green");
        squares[5][0] = new UnitSword(1, true, "green");

        squares[5][5] = new UnitVeles(-1, false, "red");
        squares[4][5] = new UnitSword(-1, false, "red");
        squares[3][5] = new UnitSword(-1, false, "red");
        squares[2][5] = new UnitVeles(-1, false, "red");
        squares[1][5] = new UnitVeles(-1, false, "red");
        squares[0][5] = new UnitSword(-1, false, "red");
        this.setSize(6 * 64, 6 * 64);
        this.addMouseListener(new MouseAdapter() {

            Point mousePressedLocation = null;

            @Override
            public void mousePressed(MouseEvent e) {
                Point x = e.getPoint();
                Point a = new Point(x.x / 64, x.y / 64);
                if(a.x < X && a.y < Y)
                mousePressedLocation = a;
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (mousePressedLocation == null) {
                    return;
                }
                Point x = e.getPoint();
                Point a = new Point(x.x / 64, x.y / 64);
                if (squares[mousePressedLocation.x][mousePressedLocation.y] != null) {
                    Point dif = new Point(a.x - mousePressedLocation.x, a.y - mousePressedLocation.y);
                    ArrayList<Point> possibleMoves = squares[mousePressedLocation.x][mousePressedLocation.y].getMovements();
                    if (possibleMoves.contains(dif) && a.x < X && a.y < Y && a.x >= 0 && a.y >= 0) {
                        if (squares[mousePressedLocation.x][mousePressedLocation.y].player == currentPlayer) {
                            if((currentPlayer ? greenMover : redMover) == null){
                                Move m = new Move(mousePressedLocation, a, possibleMoves.indexOf(dif));
                                Board.this.makeMove(m);
                            }
                        }
                    }
                }
                mousePressedLocation = null;
            }
        });
    }

    public boolean getCurrentPlayer(){
        return currentPlayer;
    }
    public Unit getSquare(int x, int y){
        return squares[x][y];
    }

    @Override
    public void paint(Graphics g) {
        for (int a = 0; a < X; a++) {
            for (int b = 0; b < Y; b++) {
                Color z;
                if ((a - b) % 2 == 0) {
                    z = new Color(255, 255, 255);
                } else {
                    z = new Color(0, 0, 0);
                }
                g.setColor(z);
                g.fillRect(a * 64, b * 64, (a + 1) * 64, (b + 1) * 64);
            }
        }
        g.setColor(Color.BLACK);
        for (int a = 0; a < X; a++) {
            g.drawLine(0, a * 64, 6 * 64, a * 64);
            g.drawLine(a * 64, 0, a * 64, 6 * 64);
            for (int b = 0; b < Y; b++) {
                if (squares[a][b] != null) {
                    squares[a][b].icon.paintIcon(this, g, a * 64, b * 64);
                }
            }
        }
    }

    public boolean isCurrentPlayer() {
        return currentPlayer;
    }

    void makeMove(Point a, Point b, int move) {
        squares[b.x][b.y] = squares[a.x][a.y];
        squares[a.x][a.y] = null;
        squares[b.x][b.y].move(move);
        currentPlayer = !currentPlayer;
        checkGameEnd();
        this.repaint();
        if((currentPlayer ? greenMover : redMover)!=null){
            makeMove((currentPlayer ? greenMover : redMover).getMove(this.clone()));
        }
    }

    void makeMove(Move x){
        makeMove(x.a, x.b, x.move);
    }

    @Override
    protected Board clone(){
        Board x = new Board();
        for(int a = 0 ; a < x.X ; a++){
            for(int b = 0 ; b < x.Y ; b++){
                x.squares[a][b] = squares[a][b];
                x.currentPlayer = currentPlayer;
                x.redMover = null;
                x.greenMover = null;
            }
        }
        return x;
    }

    void makeMove(int x){
        ArrayList<Move> moves = getAllPossibleMoves();
        makeMove(moves.get(x));

    }

    ArrayList<Move> getAllPossibleMoves(boolean player){
        ArrayList<Move> moves = new ArrayList<Move>();
        for(int a = 0 ; a < X ; a++){
            for(int b = 0 ; b < Y ; b++){
                Unit x = squares[a][b];
                if((x != null)&&(x.player == player)){
                    ArrayList<Point> movements = x.getMovements();
                    for(int i = 0 ; i < movements.size() ; i++){
                        Point movement = movements.get(i);
                        Point before = new Point(a,b);
                        Point after = new Point(a+movement.x, b+movement.y);
                        if(validMove(before, after)){
                            Move m = new Move(before, after, i);
                            moves.add(m);
                        }
                    }
                }
            }
        }
        return moves;
    }

    boolean validMove(Point before, Point after){
        Unit z = squares[before.x][before.y];
        if(z==null)
            return false;
        Point movement = new Point(after.x - before.x, after.y - before.y);
        if(!z.getMovements().contains(movement))
            return false;
        if(after.x < 0 || after.y < 0 || after.x >= X || after.y >= Y)
            return false;
        Unit f = squares[after.x][after.y];
        if(f!=null&&f.player == z.player)
            return false;
        else
            return true;
    }

    private void checkGameEnd() {
        //player red
        int greenMoveCount = 0;
        int redMoveCount = 0;
        for (int a = 0; a < X; a++) {
            for (int b = 0; b < Y; b++) {
                Unit x = squares[a][b];
                if(x != null){
                    ArrayList<Point> movements = x.getMovements();
                    int moveCount = 0;
                    Point  after;
                    for(Point z : movements){
                        after = new Point(z.x+a, z.y+b);
                        if(after.x >= 0 && after.y >= 0 && after.x < X && after.y < Y){
                            moveCount++;
                        }
                    }
                    if(x.player){
                        greenMoveCount += moveCount;
                    }
                    else{
                        redMoveCount += moveCount;
                    }
                }
            }
        }
        int currentPlayerMoveCount = currentPlayer ? greenMoveCount : redMoveCount;
        if(currentPlayerMoveCount > 0)
            return;
        else if(greenMoveCount == 0 && redMoveCount == 0){
            JOptionPane.showMessageDialog(this, "Game finished in a draw!", "Game is over", 1);
        }
        else if(currentPlayerMoveCount == 0){
            JOptionPane.showMessageDialog(this, (currentPlayer ? "Red" : "Green") + " player wins!", "Game is over", 1);
        }
        System.exit(0);
    }

    ArrayList<Move> getAllPossibleMoves() {
        return getAllPossibleMoves(currentPlayer);
    }
}
package periid;

import javax.swing.*;

public class Main {
    public static void main(String... args){
        JFrame frame = new JFrame("Periid, the board game!");
        frame.setResizable(false);
        Board board = new Board();
        frame.add(board);
        frame.setSize(6*64+6,6*64+26);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JOptionPane.showMessageDialog(frame, 
                "Welcome to Kran-impire`s periid!"+
                "\nThere are three kinds of pieces: swords, veles, and pawns."+
                "\nSwords are the \"+\" ones, they can move foward and to the sides. If they move to the sides, they will turn into pawns."+
                "\nVeles are the \"x\" ones, they can move diagonally foward." +
                "\nPawns are arrows, and only appear from swords that have moved to the sides. They only move straigth foward."+
                "\nIf you move one of your pieces to an square another piece allready is, the other piece is removed from the game."+
                "\nYou will win the game if your opponent run out of moves, and remenber: You will gain nothing if your pieces reach the other side!"+
                "\nHave fun! - Kran", "Welcome to Periid", 1);
    }
}
package periid;

import java.awt.Point;

public class Move {
    Point a;
    Point b;
    int move;

    public Move(Point a, Point b, int move) {
        this.a = a;
        this.b = b;
        this.move = move;
    }
}
package periid;
interface Mover {
    int getMove(Board clone);
}
package periid;

import java.awt.Point;
import java.util.ArrayList;
import javax.swing.ImageIcon;

public abstract class Unit {
    ArrayList<Point>movement;
    ImageIcon icon;
    boolean player;
    Unit(ImageIcon icon, boolean player, Point... movementPoints){
        movement = new ArrayList<Point>();
        this.player = player;
        this.icon = icon;
        for(Point movementX : movementPoints){
            this.movement.add(movementX);
        }
    }
    abstract void move(int x);
    ImageIcon getIcon(){
        return icon;
    }
    ArrayList<Point> getMovements(){
        return movement;
    }
}
package periid;

import java.awt.Point;
import javax.swing.ImageIcon;

public class UnitSword extends Unit{
    String playerName;
    UnitSword(ImageIcon icon, boolean player, int playerMoveSide){
        super(icon, player, new Point(0,playerMoveSide), new Point(+1,0), new Point(-1,0));
    }
    UnitSword(int playerMoveSide, boolean player, String playerName){
        this(new ImageIcon("resources\"+playerName+"sword.png"), player, playerMoveSide);
        this.playerName = playerName;
    }
    @Override
    void move(int x) {
        if(x != 0){
            super.movement.remove(2);
            super.movement.remove(1);
            super.icon = new ImageIcon("resources\"+playerName+"pawn.png");
        }
    }
}
package periid;

import java.awt.Point;
import javax.swing.ImageIcon;

public class UnitVeles extends Unit{
    UnitVeles(ImageIcon icon, boolean player, int playerMoveSide){
        super(icon, player, new Point(-1,playerMoveSide), new Point(+1,playerMoveSide));
    }
    UnitVeles(int playerMoveSide, boolean p, String player){
        this(new ImageIcon("resources\"+player+"veles.png"),p, playerMoveSide);
    }
    @Override
    void move(int x) {
    }
}

3 Respostas

Polimorphism

Consegui resolver adicionando super() no construtor do Move… :stuck_out_tongue:
Ainda nao sei o porque disso…

Polimorphism

Bugou de novo… mesmo erro. O bug aparece quando eu mexo as peças.

Polimorphism

Bugou de novo… mesmo erro. O bug aparece quando eu mexo as peças.

Criado 23 de maio de 2010
Ultima resposta 23 de mai. de 2010
Respostas 3
Participantes 1