Android Open Source - android-checkers-app Board






From Project

Back to project page android-checkers-app.

License

The source code is released under:

Apache License

If you think the Android project android-checkers-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.unlv.sudo.checkers.model;
/*  ww w  . j  a  va2 s  .  c  om*/
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import edu.unlv.sudo.checkers.model.exception.InvalidBoardException;

/**
 * Represents a checkers game board.
 */
public class Board {

    private int spacesPerSide;
    private Set<Piece> pieces;

    @JsonCreator
    public Board(@JsonProperty("spacesPerSide") final int spacesPerSide,
                 @JsonProperty("pieces") final Set<Piece> pieces) {

        if (this.spacesPerSide % 2 != 0) {
            throw new InvalidBoardException(spacesPerSide);
        }

        this.spacesPerSide = spacesPerSide;
        this.pieces = pieces;
    }

    public Set<Piece> getPieces() {
        return pieces;
    }

    public int getSpacesPerSide() {
        return spacesPerSide;
    }

    public Piece getPieceAtLocation(final Location location) {
        for (Piece piece : pieces) {
            if (piece.getLocation().equals(location)) {
                return piece;
            }
        }

        return null;
    }

    private static Set<Piece> initializePieces(final int spacesPerSide) {
        final Set<Piece> pieces = new HashSet<>(spacesPerSide * spacesPerSide / 2 - (2 * spacesPerSide));

        for (int y = 0; y < spacesPerSide / 2 - 1; y++) {
            for (int x = y % 2; x < spacesPerSide; x += 2) {
                final Location location = new Location(x, y);
                pieces.add(new Piece(Team.RED, location));
            }
        }

        for (int y = spacesPerSide - 1; y >= spacesPerSide / 2 + 1; y--) {
            for (int x = y % 2; x < spacesPerSide; x += 2) {
                final Location location = new Location(x, y);
                pieces.add(new Piece(Team.BLACK, location));
            }
        }

        return pieces;
    }
}




Java Source Code List

com.android.volley.AuthFailureError.java
com.android.volley.CacheDispatcher.java
com.android.volley.Cache.java
com.android.volley.DefaultRetryPolicy.java
com.android.volley.ExecutorDelivery.java
com.android.volley.NetworkDispatcher.java
com.android.volley.NetworkError.java
com.android.volley.NetworkResponse.java
com.android.volley.Network.java
com.android.volley.NoConnectionError.java
com.android.volley.ParseError.java
com.android.volley.RequestQueue.java
com.android.volley.Request.java
com.android.volley.ResponseDelivery.java
com.android.volley.Response.java
com.android.volley.RetryPolicy.java
com.android.volley.ServerError.java
com.android.volley.TimeoutError.java
com.android.volley.VolleyError.java
com.android.volley.VolleyLog.java
com.android.volley.toolbox.AndroidAuthenticator.java
com.android.volley.toolbox.Authenticator.java
com.android.volley.toolbox.BasicNetwork.java
com.android.volley.toolbox.ByteArrayPool.java
com.android.volley.toolbox.ClearCacheRequest.java
com.android.volley.toolbox.DiskBasedCache.java
com.android.volley.toolbox.HttpClientStack.java
com.android.volley.toolbox.HttpHeaderParser.java
com.android.volley.toolbox.HttpStack.java
com.android.volley.toolbox.HurlStack.java
com.android.volley.toolbox.ImageLoader.java
com.android.volley.toolbox.ImageRequest.java
com.android.volley.toolbox.JsonArrayRequest.java
com.android.volley.toolbox.JsonObjectRequest.java
com.android.volley.toolbox.JsonRequest.java
com.android.volley.toolbox.NetworkImageView.java
com.android.volley.toolbox.NoCache.java
com.android.volley.toolbox.PoolingByteArrayOutputStream.java
com.android.volley.toolbox.RequestFuture.java
com.android.volley.toolbox.StringRequest.java
com.android.volley.toolbox.Volley.java
edu.unlv.sudo.checkers.CheckersApplication.java
edu.unlv.sudo.checkers.CheckersBoard.java
edu.unlv.sudo.checkers.model.Board.java
edu.unlv.sudo.checkers.model.Game.java
edu.unlv.sudo.checkers.model.Location.java
edu.unlv.sudo.checkers.model.Piece.java
edu.unlv.sudo.checkers.model.Rules.java
edu.unlv.sudo.checkers.model.Team.java
edu.unlv.sudo.checkers.model.exception.InvalidBoardException.java
edu.unlv.sudo.checkers.model.exception.InvalidMoveException.java
edu.unlv.sudo.checkers.model.exception.OutOfTurnException.java
edu.unlv.sudo.checkers.service.GameService.java
edu.unlv.sudo.checkers.service.impl.GameServiceImpl.java
edu.unlv.sudo.checkers.util.VolleySingleton.java
edu.unlv.sudo.checkers.views.BoardView.java