private void generateGridMapping() { int x = 0; int place = 0; BoardTile boundary = new BoardTile(); boundary.id = -1; boundary.accepted_placement = false; boundary.placement_possible = false; boundary.occupied = false; foreach (BoardTile t in GameBoard.Children) { try { t.right = (BoardTile)GameBoard.Children[x + 1]; } catch (ArgumentOutOfRangeException) { t.Content = place; t.down = boundary; t.right = boundary; setBonusTripleWordScore(t); } try { t.left = (BoardTile)GameBoard.Children[x - 1]; } catch (ArgumentOutOfRangeException) { } try { t.up = (BoardTile)GameBoard.Children[x - 15]; } catch(ArgumentOutOfRangeException) { t.Content = place; t.up = boundary; } try { t.down = (BoardTile)GameBoard.Children[x + 15]; } catch (ArgumentOutOfRangeException) { if (t.id != 224) { t.Content = place; t.up = boundary; } } //North west boundary mapping if (t.id == 0) { t.Content = place; t.left = boundary; t.up = boundary; setBonusTripleWordScore(t); } //North East Boundary Mapping if (t.id < 15 && t.id != 0) { t.Content = place; t.up = boundary; if (t.id == 14) { t.Content = place; t.up = boundary; t.right = boundary; setBonusTripleWordScore(t); } } //Western boundary mappings if (t.id % 15 == 0 && t.down != boundary && t.id != 0) { t.Content = place; t.left = boundary; } else if (t.id % 15 == 0 && t.down == boundary) { t.Content = place; setBonusTripleWordScore(t); } //Eastern boundary mappings if (t.id % 15 == 14 && t.id != 0) { if (t.id == 14) { t.Content = place; t.up = boundary; t.right = boundary; setBonusTripleWordScore(t); } else if(t.id != 224) { t.Content = place; t.right = boundary; } } x++; if (t.left != boundary && t.up != boundary && t.down != boundary & t.right != boundary) { if(t.id % 16 == 0) setBonusDoubleWordScore(t); else if (t.id % 14 == 0) setBonusDoubleWordScore(t); } place++; } }
private void generateTrayFromBoard(BoardTile board_tile) { BoardTile placer = new BoardTile(); placer.Height = 60; placer.Width = 60; placer.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("tile.jpg", UriKind.Relative)) }; placer.tag = board_tile.tag; placer.Content = board_tile.ToString(); placer.Click += tileClickListener; PlayerTray.Children.Add(placer); }
private BoardTile drawTile(Letter Tag) { BoardTile placer = new BoardTile(); placer.Margin = new Thickness(2, 0, 0, 0); placer.Height = 60; placer.Width = 60; placer.tag = Tag; placer.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("tile.jpg", UriKind.Relative))}; placer.Content = placer.ToString(); return placer; }
private void flushSelectionQueue() { BoardTile[] storage = new BoardTile[selectionQueue.Count]; selectionQueue.CopyTo(storage, 0); foreach (BoardTile item in storage) { PlayerTray.Children.Add(selectionQueue.Dequeue()); } SelectedSequence.Content = ""; }
public List<BoardTile> mapTiles(String s, BoardTile tile) { List<BoardTile> return_set = new List<BoardTile>(); int counter = 0; int loc = s.IndexOf(tile.tag.letter_alpha); foreach(char c in s) { if (c == null || c == '\0') { } else { if (loc == counter) { return_set.Add(tile); } else { BoardTile temp = new BoardTile(); temp.Content = c.ToString(); temp.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("tile.jpg", UriKind.Relative)) }; temp.tray_location = -1; temp.FontWeight = FontWeights.UltraBold; temp.tag = this.getScoreKey(c.ToString()); return_set.Add(temp); } } counter++; } return return_set; }
private void drawRefresh() { for (int i = 0; i < 225; i++) { BoardTile blank = new BoardTile(); blank.Tag = new BoardTile(); blank.Height = 40; blank.Width = 40; if (i == 112) { blank.Content = "X"; } blank.Name = "GRID_" + (i + 1); blank.id = i; blank.Content = i.ToString(); blank.Click += boardTileListener; GameBoard.Children.Add(blank); } }
private void beginAISequence() { game_logic.clearBuffer(); int counter = AITray.Children.Count; AI.current_list.Clear(); fillGameTree(); for (int i = 0; i < 8 - counter; i++) { BoardTile fresh_tile = new BoardTile(); fresh_tile.tag = tile_sack.getRandomLetter(); fresh_tile.tray_location = i; AI.current_list.Add(drawTile(fresh_tile.tag)); AITray.Children.Add(drawTile(fresh_tile.tag)); //AIStatusReadout.Text += fresh_tile.tag.ToString() + " "; } this.MainWindowView.Title = "Tiles Remaining [" + this.tile_sack.getRemainingCount() + "]"; }
private void pushAdjacentsToSelection() { foreach(BoardTile tile in GameBoard.Children) { int id = tile.id; if (tile.accepted_placement == true) { if (this.hasAdjacent(id) != 0) { BoardTile placeholder = new BoardTile(); BoardTile game_piece = (BoardTile)GameBoard.Children[id + this.hasAdjacent(id)]; placeholder.id = game_piece.id; placeholder.tag = game_piece.tag; try { this.game_logic.addToSequence(placeholder); } catch (Exception) { } } else { } } } }
private void setBonusTripleWordScore(BoardTile t) { t.Background = new SolidColorBrush(Colors.Red); t.Content = "3x WS"; t.bonus_multiplier = new KeyValuePair<char, int>('W', 3); }
private KeyValuePair<bool, String> validatePlacement(List<BoardTile> candidate) { String output_word = ""; int marker = 0; //Attempt to play word selection BoardTile boundary = new BoardTile(); boundary.id = -1; boundary.accepted_placement = false; boundary.placement_possible = false; boundary.occupied = false; List<BoardTile> acceptable_roots = new List<BoardTile>(); foreach(BoardTile possible_root in GameBoard.Children) { if(possible_root.accepted_placement == true) { try { if (possible_root.up.id == -1) { if (possible_root.down.tag == null) { acceptable_roots.Add(possible_root); } else if (possible_root.left == null && possible_root.right == null) { acceptable_roots.Add(possible_root); } else { //Discard root possibility } } else if (possible_root.down.id == -1) { if (possible_root.down.tag == null) { acceptable_roots.Add(possible_root); } else if (possible_root.left == null && possible_root.right == null) { acceptable_roots.Add(possible_root); } else { //Discard root possibility } } else { if (possible_root.up.tag == null && possible_root.down.tag == null) { acceptable_roots.Add(possible_root); } else if (possible_root.left.tag == null && possible_root.right.tag == null) { acceptable_roots.Add(possible_root); } else { //Discard root possibility } } } catch(Exception) { } } //Take all possible root points //Find it's place within the candidate selection //Map the tile to the candidate, then check it's //Placement validity and return true or false //With the String as the Value return for debug } int place_marker = 0; bool exit = false; foreach(BoardTile t in candidate) { output_word += t.tag.letter_alpha; foreach (BoardTile root in acceptable_roots) { if (root.tag == t.tag) { exit = true; break; } } if (exit) { break; } else place_marker++; } foreach (BoardTile t in candidate) { int marker_id = 0; List<BoardTile> outer_storage = new List<BoardTile>(); outer_storage.AddRange(candidate); if (t.accepted_placement == true) { int counter = candidate.Count; if (t.up.accepted_placement == false && t.down.accepted_placement == false) { //This states that the north and south paths are open so far int new_loc = t.id; String x = "U"; for (int i = place_marker-1; i >= 0; i--) { if (checkMapping(outer_storage[i], new_loc, i, x) == false) { return new KeyValuePair<bool,string>(false, output_word); } else { } x = "U"; new_loc = new_loc - 15; } new_loc = t.id; int root_difference = place_marker; x = "ROOT"; for (int i = place_marker; i < candidate.Count; i++) { if (checkMapping(outer_storage[i], new_loc, i, x) == false) { return new KeyValuePair<bool, string>(false, output_word); } x = "D"; new_loc = new_loc + 15; } } else if (t.right.accepted_placement == false && t.left.accepted_placement == false) { String x = "L"; int new_loc = t.id; for (int i = place_marker-1; i >= 0; i--) { if (checkMapping(outer_storage[i], new_loc, i, x) == false) { return new KeyValuePair<bool,string>(false, output_word); } x = "L"; new_loc = new_loc - 1; } x = "ROOT"; new_loc = t.id; for (int i = place_marker; i < candidate.Count; i++) { int remaining = candidate.Count - i; if (checkMapping(outer_storage[i], new_loc, remaining, x) == false) { return new KeyValuePair<bool,string>(false, output_word); } x = "R"; new_loc = new_loc + 1; } } } } //this.AIPlayedWords.Items.Add(output_word + " - " + game_logic.score); return new KeyValuePair<bool, string>(true, output_word); }
private void setBonusDoubleWordScore(BoardTile t) { if(t.id == 112) { t.Content = "X"; t.FontWeight = FontWeights.UltraBold; t.Background = new SolidColorBrush(Colors.Yellow); } else { t.Background = new SolidColorBrush(Colors.Pink); t.Content = "2x WS"; t.bonus_multiplier = new KeyValuePair<char, int>('W', 2); } }
private void resetTray() { try { int count = selectionQueue.Count; BoardTile[] storage = new BoardTile[GameBoard.Children.Count]; GameBoard.Children.CopyTo(storage, 0); foreach (BoardTile t in storage) { if (t.accepted_placement == false && t.occupied==true) { this.generateTrayFromBoard(t); this.resetBoardTile(t); game_logic.selection.Clear(); } } } catch (Exception) { } this.flushSelectionQueue(); }
public void addToSequence(BoardTile t) { this.selection.Add(t); }
private bool hasAdjacentWest(BoardTile t) { //If there exists a tile below this tile //It is included in the current input String if (t.left.tag != null) { return true; } return false; }
private bool checkMapping(BoardTile t, int loc, int remaining_places, String direction) { try { BoardTile placer = drawTile(t.tag); placer.id = loc; placer.Content = t.Content; BoardTile boundary = new BoardTile(); boundary.id = -1; foreach(BoardTile board_tile in GameBoard.Children) { if (loc < 255 && loc >= 0) { if (board_tile.id == loc) { if(direction.Equals("L") || direction.Equals("R")) { if(direction.Equals("R") && board_tile.right.tag != null) { return false; } else if (direction.Equals("L") && board_tile.left.tag != null) { return false; } if (board_tile.up.tag != null || board_tile.down.tag != null) { return false; } } else if (direction.Equals("U") || direction.Equals("D")) { if (direction.Equals("U") && board_tile.up.tag != null) { return false; } else if (direction.Equals("D") && board_tile.down.tag != null) { return false; } if (board_tile.left.tag != null || board_tile.right.tag != null) { return false; } } if ((board_tile.id % 15 == 0 || board_tile.id % 15 == 14) && remaining_places > 0) { //Boundary violation set int j = 0; return false; } if ((board_tile.up == boundary || board_tile.down == boundary) && remaining_places > 0) { //Boundary violation set int j = 0; return false; } if(board_tile.id < 15 && remaining_places > 0) { return false; } return true; } } else return false; } } catch (Exception e) { return false; } return false; }
private void mapAITileToBoard(BoardTile t, int loc) { try { BoardTile placer = drawTile(t.tag); placer.id = loc; placer.Content = t.Content; foreach(BoardTile inner_set in GameBoard.Children) { if (inner_set.id == loc) { //inner_set.left = (BoardTile)GameBoard.Children[loc - 1]; //inner_set.right = (BoardTile)GameBoard.Children[loc + 1]; //inner_set.up = (BoardTile)GameBoard.Children[loc - 15]; //inner_set.down = (BoardTile)GameBoard.Children[loc + 15]; inner_set.tag = placer.tag; inner_set.Content = inner_set.tag.letter_alpha; inner_set.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("tile.jpg", UriKind.Relative))}; inner_set.FontWeight = FontWeights.UltraBold; inner_set.accepted_placement = true; inner_set.placement_possible = false; } } } catch (Exception e) { } }
private void drawBegin() { for (int i = 0; i < 225; i++) { BoardTile blank = new BoardTile(); blank.Tag = new BoardTile(); blank.Height = 40; blank.Width = 40; if (i == 112) { blank.Content = "X"; } blank.Name = "GRID_" + (i + 1); blank.Content = i.ToString(); blank.id = i; blank.Click += boardTileListener; blank.MouseEnter += tileDebug; blank.FontWeight = FontWeights.Bold; GameBoard.Children.Add(blank); } generateGridMapping(); }
private void resetBoardTile(BoardTile board_tile) { BoardTile blank = new BoardTile(); blank.Tag = new BoardTile(); blank.Height = 40; blank.Width = 40; blank.BorderBrush = new SolidColorBrush(Colors.Gray); if (board_tile.id == 112) { blank.Content = "X"; } blank.Name = board_tile.Name; blank.id = board_tile.id; blank.Click += boardTileListener; blank.bonus_multiplier = board_tile.bonus_multiplier; blank.placement_possible = true; blank.Content = board_tile.id.ToString(); GameBoard.Children.RemoveAt(board_tile.id); GameBoard.Children.Insert(board_tile.id, blank); foreach (BoardTile t in GameBoard.Children) { if(t.placement_possible == true && t.accepted_placement == false) { t.BorderBrush = null; } } }
public List<BoardTile> getTilesFromString(String s, BoardTile root, int loc, List<BoardTile> score_index, int tray_location) { int counter=0; List<BoardTile> return_set = new List<BoardTile>(); foreach (Char c in s) { if (c != null && c != '\0') { if (loc == counter) { return_set.Add(root); } else { BoardTile temp = new BoardTile(); temp.Content = c.ToString(); temp.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("tile.jpg", UriKind.Relative)) }; temp.tray_location = tray_location; temp.FontWeight = FontWeights.UltraBold; temp.tag = this.getScoreKey(c.ToString()); return_set.Add(temp); } counter++; } } return return_set; }