Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions GITCOMMANDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#### Branch. Lag alltid en ny branch hver gang du jobber med noe nytt.
- git branch // Viser de tilgjengelige branchene
- git checkout -b <navn-på-branch> // lager ny branch
- git branch -d <branch_name> // sletter branch

#### Navn på branch
- Kun små bokstaver og "-" indikerer mellomrom
- initialler/navn-på-branch
- Eksempel: hnl/oppdatere-readme

#### Hvordan pulle(hente) endringer. Gjøres hver gang man skal jobbe.
- git status
- git switch main
- git pull
- git switch <ønsket branch>
- git main //sørge for at din branch er oppdatert med main

#### Hvordan pushe endringer.
- git add . // legger til endringer i staging area
- git commit -m “Hva du har gjort” // lagrer add endringene i den lokale git historien din.
- git push -u origin <branch_navn> //sender de lokale endringene i git historien til de eksterne repositoriet. Nå kan andre hente endringene. Husk å lage en pull request. Bare git push hvis man har pushet branchen før.
- Lag en pull request på github hvor du spør en annen om å godkjenne hva du har gjort

dette er en test
50 changes: 50 additions & 0 deletions Model/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package Model;



public class Board {
Spot[][] boxes;

public Board()
{
this.resetBoard();
}

public Spot getBox(int x, int y)
{

if (x < 0 || x > 7 || y < 0 || y > 7) {
throw new Exception("Index out of bound");
}

return boxes[x][y];
}

public void resetBoard()
{
// initialize white pieces
boxes[0][0] = new Spot(0, 0, new Rook(true));
boxes[0][1] = new Spot(0, 1, new Knight(true));
boxes[0][2] = new Spot(0, 2, new Bishop(true));
//...
boxes[1][0] = new Spot(1, 0, new Pawn(true));
boxes[1][1] = new Spot(1, 1, new Pawn(true));
//...

// initialize black pieces
boxes[7][0] = new Spot(7, 0, new Rook(false));
boxes[7][1] = new Spot(7, 1, new Knight(false));
boxes[7][2] = new Spot(7, 2, new Bishop(false));
//...
boxes[6][0] = new Spot(6, 0, new Pawn(false));
boxes[6][1] = new Spot(6, 1, new Pawn(false));
//...

// initialize remaining boxes without any piece
for (int i = 2; i < 6; i++) {
for (int j = 0; j < 8; j++) {
boxes[i][j] = new Spot(i, j, null);
}
}
}
}
56 changes: 56 additions & 0 deletions Model/King.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package Model;

public class King extends Piece {
private boolean castlingDone = false;

public King(boolean white)
{
super(white);
}

public boolean isCastlingDone()
{
return this.castlingDone;
}

public void setCastlingDone(boolean castlingDone)
{
this.castlingDone = castlingDone;
}

@Override
public boolean canMove(Board board, Spot start, Spot end)
{
// we can't move the piece to a Spot that
// has a piece of the same color
if (end.getPiece().isWhite() == this.isWhite()) {
return false;
}

int x = Math.abs(start.getX() - end.getX());
int y = Math.abs(start.getY() - end.getY());
if (x + y == 1) {
// check if this move will not result in the king
// being attacked if so return true
return true;
}

return this.isValidCastling(board, start, end);
}

private boolean isValidCastling(Board board, Spot start, Spot end)
{

if (this.isCastlingDone()) {
return false;
}

// Logic for returning true or false
}

public boolean isCastlingMove(Spot start, Spot end)
{
// check if the starting and
// ending position are correct
}
}
22 changes: 22 additions & 0 deletions Model/Knight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Model;

public class Knight extends Piece {
public Knight(boolean white)
{
super(white);
}

@Override
public boolean canMove(Board board, Spot start, Spot end)
{
// we can't move the piece to a spot that has
// a piece of the same colour
if (end.getPiece().isWhite() == this.isWhite()) {
return false;
}

int x = Math.abs(start.getX() - end.getX());
int y = Math.abs(start.getY() - end.getY());
return x * y == 2;
}
}
34 changes: 34 additions & 0 deletions Model/Piece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package Model;

public abstract class Piece {

private boolean killed = false;
private boolean white = false;

public Piece(boolean white)
{
this.setWhite(white);
}

public boolean isWhite()
{
return this.white;
}

public void setWhite(boolean white)
{
this.white = white;
}

public boolean isKilled()
{
return this.killed;
}

public void setKilled(boolean killed)
{
this.killed = killed;
}

public abstract boolean canMove(Board board, Spot start, Spot end);
}
46 changes: 46 additions & 0 deletions Model/Spot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package Model;



public class Spot {
private Piece piece;
private int x;
private int y;

public Spot(int x, int y, Piece piece)
{
this.setPiece(piece);
this.setX(x);
this.setY(y);
}

public Piece getPiece()
{
return this.piece;
}

public void setPiece(Piece p)
{
this.piece = p;
}

public int getX()
{
return this.x;
}

public void setX(int x)
{
this.x = x;
}

public int getY()
{
return this.y;
}

public void setY(int y)
{
this.y = y;
}
}