public bool won(int Player) { int cont_X = BOARD.contPieces(PLAYER1); int cont_O = BOARD.contPieces(PLAYER2); if (PLAYER1 == Player && cont_O == 0 && cont_X > 0) { return(true); } else if (PLAYER2 == Player && cont_X == 0 && cont_O > 0) { return(true); } if (PLAYER1 == Player && ACTUAL_PLAYER == PLAYER2) { if (cannotMove(PLAYER2)) { WINNER = PLAYER1; return(true); } } if (PLAYER2 == Player && ACTUAL_PLAYER == PLAYER1) { if (cannotMove(PLAYER1)) { WINNER = PLAYER2; return(true); } } return(false); }
public override bool add(int x, int y, int Player) { TictactoePiece P = null; if (Player == PLAYER1) { P = new TictactoePiece("X", PLAYER1); } else if (Player == PLAYER2) { P = new TictactoePiece("O", PLAYER2); } else { Console.WriteLine("Invalid player: '" + Player + "'. Players: '" + PLAYER1 + "' and '" + PLAYER2 + "'."); return(false); } if (canAdd(x, y, (Piece)P)) { if (BOARD.addPiece(x, y, (Piece)P)) { } else { Console.WriteLine("BLASFEMIA!!!"); } if (gameEnded()) { Console.WriteLine("End game. Winner: " + WINNER); } CONT_ID++; return(true); } return(false); }
private bool inCheckMate(int Player) { Position p = findKing(Player); if (!(inCheck(Player))) { return(false); } int KingX = p.X; int KingY = p.Y; if (canMoveAnywhere(KingX, KingY, ChessPiece.KING)) { return(false); } for (int cx = 0; cx <= 8; cx++) { for (int cy = 0; cy <= 8; cy++) { if (BOARD.getPiece(cx, cy).getClass2().Equals(ChessPiece.getClass())) { ChessPiece P1 = (ChessPiece)BOARD.getPiece(cx, cy); if ((P1.PLAYER == Player && !P1.get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase))) { if (canMoveAnywhere(cx, cy, P1.get_type())) { return(false); } } } } } return(true); }
public void insertPieces() { for (int cont = 0; cont < 8; cont++) { BOARD.addPiece(1, cont, new ChessPiece("O", PLAYER2, ChessPiece.PAWN)); BOARD.addPiece(6, cont, new ChessPiece("X", PLAYER1, ChessPiece.PAWN)); } for (int cont = 0; cont < 2; cont++) { BOARD.addPiece(0, Math.Abs(7 * cont), new ChessPiece("O", PLAYER2, ChessPiece.ROOK)); BOARD.addPiece(7, Math.Abs(7 * cont), new ChessPiece("X", PLAYER1, ChessPiece.ROOK)); BOARD.addPiece(0, Math.Abs(7 * cont - 1), new ChessPiece("O", PLAYER2, ChessPiece.KNIGHT)); BOARD.addPiece(7, Math.Abs(7 * cont - 1), new ChessPiece("X", PLAYER1, ChessPiece.KNIGHT)); BOARD.addPiece(0, Math.Abs(7 * cont - 2), new ChessPiece("O", PLAYER2, ChessPiece.BISHOP)); BOARD.addPiece(7, Math.Abs(7 * cont - 2), new ChessPiece("X", PLAYER1, ChessPiece.BISHOP)); } BOARD.addPiece(0, 3, new ChessPiece("O", PLAYER2, ChessPiece.QUEEN)); BOARD.addPiece(0, 4, new ChessPiece("O", PLAYER2, ChessPiece.KING)); BOARD.addPiece(7, 3, new ChessPiece("X", PLAYER1, ChessPiece.QUEEN)); BOARD.addPiece(7, 4, new ChessPiece("X", PLAYER1, ChessPiece.KING)); }
public override bool canMove(int x1, int y1, int x2, int y2, int Player) { if (canMoveAux(x1, y1, x2, y2, Player)) { Piece eaten_piece = BOARD.getPiece(x2, y2); Board BOARD_BACKUP = BOARD.backup(); if (canMoveAux(x1, y1, x2, y2, Player)) { if ((y1 != y2) && eaten_piece.getClass2() == NullPiece.getClass() && ((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase)) { eaten_piece = BOARD.getPiece(x1, y2); BOARD.removePiece(x1, y2); } BOARD.movePiece(x1, y1, x2, y2); if (inCheck(Player)) { BOARD = BOARD_BACKUP; return(false); } else { BOARD = BOARD_BACKUP; return(true); } } BOARD = BOARD_BACKUP; } return(false); }
private List <Node> addNodeToBoard(BOARD board) { mindmap.createBoard(board); List <Node> listNode = new List <Node>(); List <int> idParents = new List <int>(); foreach (TOPIC topic in TOPICcontroller.getListTopic(board.ID)) { Color bcolor = ColorTranslator.FromHtml(topic.BACKCOLOR); Color fcolor = ColorTranslator.FromHtml(topic.FORECOLOR); Color pcolor = ColorTranslator.FromHtml(topic.COLOR_PATH); mPath path = new mPath(topic.SIZE_PATH, pcolor, topic.STYLE_PATH); bool flag = false; foreach (Node n in listNode) { if (topic.ID_PARENT == n.id) { Node node = mindmap.createNode(topic.ID, topic.LABEL_TP, new Point(topic.POS_X, topic.POS_Y), new Size(topic.WIDTH, topic.HEIGHT), bcolor, fcolor, path, (float)topic.SIZE, n, topic.TEXT_SIZE, topic.SHAPE, topic.FONT); mindmap.board.picbox.Controls.Add(node); listNode.Add(node); flag = true; break; } } if (!flag) { Node node = mindmap.createNode(topic.ID, topic.LABEL_TP, new Point(topic.POS_X, topic.POS_Y), new Size(topic.WIDTH, topic.HEIGHT), bcolor, fcolor, path, (float)topic.SIZE, null, topic.TEXT_SIZE, topic.SHAPE, topic.FONT); mindmap.board.picbox.Controls.Add(node); listNode.Add(node); } } return(listNode); }
public List <TOPIC> convertNodeToTopic(BOARD board, List <Node> listNode) { List <TOPIC> listTopic = new List <TOPIC>(); foreach (Node node in listNode) { TOPIC topic = new TOPIC(); topic.ID = node.id; topic.ID_BOARD = board.ID; topic.ID_PARENT = node.parent.id; topic.LABEL_TP = node.Text; topic.POS_X = node.Location.X; topic.POS_Y = node.Location.Y; topic.SHAPE = node.shape; topic.SIZE = node.size; topic.SIZE_PATH = node.path.size; topic.TEXT_SIZE = (int)node.Font.Size; topic.STYLE_PATH = node.path.type; topic.COLOR_PATH = HexConverter(node.path.color); topic.BACKCOLOR = HexConverter(node.BackColor); topic.FORECOLOR = HexConverter(node.ForeColor); topic.WIDTH = node.Width; topic.HEIGHT = node.Height; topic.FONT = node.Font.FontFamily.Name; topic.BOARD = board; listTopic.Add(topic); } return(listTopic); }
public IHttpActionResult PutBOARD(long id, BOARD bOARD) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bOARD.id) { return(BadRequest()); } db.Entry(bOARD).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BOARDExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool canAdd(int x, int y, Piece P) { if ((GAME_ENDED) || (WAITING_PLAYERS)) { return(false); } if (BOARD.getPiece(x, y).getClass2() != NullPiece.getClass()) { return(false); } int cont_O = BOARD.contPieces(PLAYER2); int cont_X = BOARD.contPieces(PLAYER1); if (P.getPlayer() == PLAYER2) { if (cont_O == cont_X - 1) { ACTUAL_PLAYER = PLAYER1; return(true); } } else if ((P.getPlayer() == PLAYER1)) { if (cont_O == cont_X) { ACTUAL_PLAYER = PLAYER2; return(true); } } return(false); }
public bool burn(int x, int y) { Console.WriteLine("Burning: " + x + "," + y); Console.WriteLine(BOARD.getPiece(x, y).getClass2()); if (BOARD.getPiece(x, y).getClass2() == DeflexionPiece.getClass()) { String deleted_type = ((DeflexionPiece)BOARD.getPiece(x, y)).get_type(); int deleted_player = ((DeflexionPiece)BOARD.getPiece(x, y)).getPlayer(); if (BOARD.removePiece(x, y)) { if (deleted_type.Equals(DeflexionPiece.PHAROAH, StringComparison.CurrentCultureIgnoreCase)) { GAME_ENDED = true; if (deleted_player == PLAYER1) { WINNER = PLAYER2; } else if (deleted_player == PLAYER2) { WINNER = PLAYER1; } else { Console.WriteLine("Invalid player - burn end game"); } Console.WriteLine("End game. Winner: " + WINNER); } CONT_ID++; return(true); } } return(false); }
public bool canEat(int x, int y) { if (BOARD.getPiece(x, y).getClass2() == CheckersPiece.getClass()) { return(true); } return(false); }
public void createBoard(BOARD b) { Color color = System.Drawing.ColorTranslator.FromHtml(b.COLOR); Board board = new Board(b.ID, color, new Point(0, 100), new Size(b.WIDTH, b.HEIGHT)); this.board = board; this.Controls.Add(this.board); }
public ActionResult boardDel(int id) { BOARD board = conn.BOARD.Find(id); conn.BOARD.Remove(board); conn.SaveChanges(); return(View()); }
public IHttpActionResult GetBOARD(long id) { BOARD bOARD = db.BOARD.Find(id); if (bOARD == null) { return(NotFound()); } return(Ok(bOARD)); }
public bool canEat(int x, int y, int x2, int y2, int Player) { if (BOARD.validCell(x2, y2)) { if (BOARD.getPiece(x2, y2).getClass2() == ChessPiece.getClass()) { return(canMove(x, y, x2, y2, Player)); } } return(false); }
public void SaveBoard(BoardDto board) { var entity = new BOARD { EMAIL = this.UserEmail, BOARD_SEQ = board.boardSeq, BOARD_TITLE = board.boardTitle }; _context.BOARD.Add(entity); _context.SaveChanges(); }
public IHttpActionResult PostBOARD(BOARD bOARD) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BOARD.Add(bOARD); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = bOARD.id }, bOARD)); }
public void update() { //storage STORAGE storage = new STORAGE(); storage.ID_BOARD = mindmap.board.id; storage.NAME_S = STORAGEcontroller.getNameStorage(storage.ID_BOARD); storage.DATE_MODIFIED = DateTime.Now; //board BOARD board = new BOARD(); board.ID = storage.ID_BOARD; board.WIDTH = mindmap.board.picbox.Width; board.HEIGHT = mindmap.board.picbox.Height; board.COLOR = HexConverter(mindmap.board.picbox.BackColor); //node TOPICcontroller.removeNode(convertNodeToTopic(board, mindmap.listDelete)); mindmap.listDelete.Clear(); List <TOPIC> existTopics = new List <TOPIC>() { }; existTopics = TOPICcontroller.getListTopic(board.ID); List <TOPIC> updateTopics = new List <TOPIC>(); List <TOPIC> newTopics = new List <TOPIC>(); newTopics = convertNodeToTopic(board, this.listNode); foreach (TOPIC topic in newTopics.ToList()) { foreach (TOPIC etopic in existTopics.ToList()) { if (topic.ID == etopic.ID) { updateTopics.Add(topic); newTopics.Remove(topic); } } } TOPICcontroller.updateListTopic(updateTopics); TOPICcontroller.addListTopic(newTopics, board.ID); BOARDcontroller.updateBoard(board); if (STORAGEcontroller.updateStorage(storage)) { MessageBox.Show("saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public ActionResult boardAdd([System.Web.Http.FromBody] boardManager model) { if (ModelState.IsValid) { BOARD bo = new BOARD(); bo.B_NAME = model.B_NAME; bo.B_CONTENTS = model.B_CONTENTS; conn.BOARD.Add(bo); conn.SaveChanges(); return(RedirectToAction("boardManager")); } return(View()); }
public void insertPieces() { for (int cont = 0; cont < 4; cont++) { BOARD.addPiece(0, cont * 2, new CheckersPiece("x", PLAYER1, CheckersPiece.SIMPLE)); BOARD.addPiece(1, 1 + cont * 2, new CheckersPiece("x", PLAYER1, CheckersPiece.SIMPLE)); BOARD.addPiece(2, cont * 2, new CheckersPiece("x", PLAYER1, CheckersPiece.SIMPLE)); BOARD.addPiece(5, 1 + cont * 2, new CheckersPiece("o", PLAYER2, CheckersPiece.SIMPLE)); BOARD.addPiece(6, cont * 2, new CheckersPiece("o", PLAYER2, CheckersPiece.SIMPLE)); BOARD.addPiece(7, 1 + cont * 2, new CheckersPiece("o", PLAYER2, CheckersPiece.SIMPLE)); } }
public IHttpActionResult DeleteBOARD(long id) { BOARD bOARD = db.BOARD.Find(id); if (bOARD == null) { return(NotFound()); } db.BOARD.Remove(bOARD); db.SaveChanges(); return(Ok(bOARD)); }
public bool canRotate(int x, int y, int Player) { if (BOARD.validCell(x, y)) { if (BOARD.getPiece(x, y).getClass2() == DeflexionPiece.getClass()) { if (((DeflexionPiece)BOARD.getPiece(x, y)).get_type().Equals(DeflexionPiece.DJED, StringComparison.CurrentCultureIgnoreCase) || ((DeflexionPiece)BOARD.getPiece(x, y)).get_type().Equals(DeflexionPiece.PYRAMID, StringComparison.CurrentCultureIgnoreCase)) { return(true); } } } return(false); }
public override bool move(int x1, int y1, int x2, int y2, int Player) { if (canMove(x1, y1, x2, y2, Player)) { BOARD.movePiece(x1, y1, x2, y2); if ((Player == PLAYER1) && (x2 == 7)) { ((CheckersPiece)BOARD.getPiece(x2, y2)).TYPE = CheckersPiece.CHECKER; } else if ((Player == PLAYER2) && (x2 == 0)) { ((CheckersPiece)BOARD.getPiece(x2, y2)).TYPE = CheckersPiece.CHECKER; } if (Math.Abs(x2 - x1) == 2 && Math.Abs(y2 - y1) == 2) { int x_adversary = x1 + (x2 - x1) / 2; int y_adversary = y1 + (y2 - y1) / 2; eat(x_adversary, y_adversary); if (isPossibleToKeepEating(x2, y2, Player)) { EAT_MOVE = true; EAT_PIECE = BOARD.getPiece(x2, y2); CONT_ID++; if (gameEnded()) { Console.WriteLine("End game. Winner: " + WINNER); } return(true); } } EAT_MOVE = false; if (Player == PLAYER1) { ACTUAL_PLAYER = PLAYER2; } else { ACTUAL_PLAYER = PLAYER1; } CONT_ID++; if (gameEnded()) { Console.WriteLine("End game. Winner: " + WINNER); } return(true); } return(false); }
public override bool add(int x, int y, int Player) { TictactoePiece P = null; if (Player == PLAYER1) { P = new TictactoePiece("+", PLAYER1); } else if (Player == PLAYER2) { P = new TictactoePiece("-", PLAYER2); } else { Console.WriteLine("Invalid player: '" + Player + "'. Players: '" + PLAYER1 + "' and '" + PLAYER2 + "'."); return(false); } if (canAdd(x, y, (Piece)P)) { if (BOARD.addPiece(x, y, (Piece)P)) { } else { Console.WriteLine("BLASFEMIA!!!"); } if ((BOARD.contPieces(new TictactoePiece("", -1)) == 9) && WINNER == -1) { DRAWN_GAME = true; GAME_ENDED = true; LAST_MESSAGE = "DRAWN GAME"; } if (gameEnded()) { if (DRAWN_GAME) { Console.WriteLine("End game. " + LAST_MESSAGE); } else { Console.WriteLine("End game. Winner: " + WINNER); } } CONT_ID++; return(true); } return(false); }
public bool won(int Player) { int cont_X = BOARD.contPieces(PLAYER1); int cont_O = BOARD.contPieces(PLAYER2); if (PLAYER1 == Player && cont_O == 0 && cont_X > 0) { return(true); } else if (PLAYER2 == Player && cont_X == 0 && cont_O > 0) { return(true); } return(false); }
private void saveBoard(int id) { BOARD board = new BOARD(); board.ID = id; board.WIDTH = mindmap.board.picbox.Width; board.HEIGHT = mindmap.board.picbox.Height; board.COLOR = HexConverter(mindmap.board.picbox.BackColor); saveListNode(board); BOARDcontroller.AddBoard(board); mindmap.board.id = id; }
public bool eat(int x, int y) { if (BOARD.getPiece(x, y).getClass2() == ChessPiece.getClass()) { if (BOARD.removePiece(x, y)) { if (gameEnded()) { Console.WriteLine("End game. Winner: " + WINNER); } return(true); } } return(false); }
public override bool add(int x, int y, int Player) { NovoJogoPiece P = null; if (Player == PLAYER1) { P = new NovoJogoPiece("X", PLAYER1, NovoJogoPiece.PECA_X); } else if (Player == PLAYER2) { P = new NovoJogoPiece("O", PLAYER2, NovoJogoPiece.PECA_O); } else { Console.WriteLine("O Jogador que esta tentando jogar nao pertence ao jogo: '" + Player + "'. Jogadores no jogo: '" + PLAYER1 + "' e '" + PLAYER2 + "'."); return(false); } if (canAdd(x, y, (Piece)P)) { if (!BOARD.addPiece(x, y, (Piece)P)) { } else { Console.WriteLine("Nao foi possivel adicionar a peca. Problema desconhecido."); } if ((BOARD.contPieces(new NovoJogoPiece("", -1, "")) == 9) && WINNER == -1) { DRAWN_GAME = true; GAME_ENDED = true; LAST_MESSAGE = "VELHA"; } if (gameEnded()) { if (DRAWN_GAME) { Console.WriteLine("Jogo encerrado. " + LAST_MESSAGE); } else { Console.WriteLine("Jogo encerrado. Vencedor: " + WINNER); } } CONT_ID++; return(true); } return(false); }
public static bool updateBoard(BOARD board) { try { using (var _context = new MINDMAPEntities()) { _context.BOARDs.AddOrUpdate(board); _context.SaveChanges(); return(true); } } catch { return(false); } }
public Position findKing(int Player) { for (int x = 0; x <= 8; x++) { for (int y = 0; y <= 8; y++) { if (BOARD.getPiece(x, y).getClass2() != NullPiece.getClass()) { if ((((ChessPiece)BOARD.getPiece(x, y)).get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase)) && ((ChessPiece)BOARD.getPiece(x, y)).PLAYER == Player) { return(new Position(x, y)); } } } } return(new Position(-1, -1)); }