diff --git a/GITCOMMANDS.md b/GITCOMMANDS.md new file mode 100644 index 0000000..c7bbb6b --- /dev/null +++ b/GITCOMMANDS.md @@ -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 // lager ny branch +- git branch -d // 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 //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 \ No newline at end of file diff --git a/Model/Board.java b/Model/Board.java new file mode 100644 index 0000000..b56f5a5 --- /dev/null +++ b/Model/Board.java @@ -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); + } + } + } +} diff --git a/Model/King.java b/Model/King.java new file mode 100644 index 0000000..592c279 --- /dev/null +++ b/Model/King.java @@ -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 + } +} diff --git a/Model/Knight.java b/Model/Knight.java new file mode 100644 index 0000000..42084e1 --- /dev/null +++ b/Model/Knight.java @@ -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; + } +} diff --git a/Model/Piece.java b/Model/Piece.java new file mode 100644 index 0000000..7cb4d25 --- /dev/null +++ b/Model/Piece.java @@ -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); +} diff --git a/Model/Spot.java b/Model/Spot.java new file mode 100644 index 0000000..73aba73 --- /dev/null +++ b/Model/Spot.java @@ -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; + } +}