ernesto logo
Torna al Magazine
Automazione illuminazione: come trovare elettricisti
consigli
Automazione illuminazione: come trovare elettricisti

Come Trovare Elettricisti per l'Automazione dell'Illuminazione

Come Trovare un Elettricista per Automatizzare l'Illuminazione.

Scopri come trovare elettricisti esperti per l'automazione dell'illuminazione e rendere la tua casa più intelligente. Questo articolo offre suggerimenti utili e strategie per selezionare i professionisti giusti, garantendo risultati ottimali per i tuoi progetti di ristrutturazione e miglioramento domestico.

Trova professionisti vicino a te

Trova professionisti
package edu.cmu.cs.cs214.hw4.core; import java.io.File; import java.io.FileNotFoundException; import java.util.*; /** * Class that defines the game Scrabble. */ public class ScrabbleGame { private static final int INITIAL_TILES = 7; private static final int GAME_SIZE = 4; private static final int MIN_PLAYERS = 2; private static final int MAX_PLAYERS = 4; private static final int POINTS_PER_TILE = 1; private static final int DOUBLE_WORD = 2; private static final int TRIPLE_WORD = 3; private static final int DOUBLE_LETTER = 2; private static final int TRIPLE_LETTER = 3; private static final int TOTAL_TILES = 100; private final Board board; private int numPlayers; private List players; private Bag bag; private Dictionary dictionary; private int turn; private boolean gameOver; private List words; private boolean firstMove; /** * Constructor for Scrabble Game. * * @param playerNames names of players * @throws IllegalArgumentException if playerNames size is less than two or greater than four. */ public ScrabbleGame(List playerNames) { if (playerNames.size() < MIN_PLAYERS || playerNames.size() > MAX_PLAYERS) { throw new IllegalArgumentException("Number of players is not valid"); } board = new Board(); numPlayers = playerNames.size(); players = new ArrayList<>(); for (String playerName : playerNames) { Player player = new Player(playerName); players.add(player); } bag = new Bag(TOTAL_TILES); dictionary = new Dictionary(); turn = 0; gameOver = false; words = new ArrayList<>(); firstMove = true; } /** * Method to start the game. */ public void startGame() { for (int i = 0; i < numPlayers; i++) { for (int j = 0; j < INITIAL_TILES; j++) { Tile tile = bag.drawTile(); players.get(i).addTile(tile); } } } /** * Method to check if move is valid. * * @param move move that needs to be checked * @return true if move is valid else false */ public boolean checkValidMove(Move move) { boolean validMove = false; if (firstMove) { validMove = move.isValidFirstMove(GAME_SIZE); firstMove = false; } else { validMove = move.isValidMove(board); if (validMove) { validMove = move.isMeldValid(dictionary); } } if (validMove) { words = move.getWords(); board.placeTiles(move); bag.addTiles(move.getTiles()); return true; } return false; } /** * Method to get the current player. * * @return current player */ public Player getCurrentPlayer() { return players.get(turn); } /** * Method to get the board of the game. * * @return board */ public Board getBoard() { return board; } /** * Method to get the current turn. * * @return turn */ public int getTurn() { return turn; } /** * Method to check if game is over. * * @return true if game is over else false */ public boolean isGameOver() { return gameOver; } /** * Method to get the words formed in the last move. * * @return list of words */ public List getWords() { return words; } /** * Method to end the turn. */ public void endTurn() { turn = (turn + 1) % numPlayers; getCurrentPlayer().addTiles(bag.drawTiles(INITIAL_TILES - getCurrentPlayer().getHandSize())); if (bag.isEmpty()) { gameOver = true; } } /** * Method to get the scores of all the players. * * @return map of players and their scores */ public Map getScores() { Map scoresMap = new HashMap<>(); for (Player player : players) { scoresMap.put(player.getName(), player.getScore()); } return scoresMap; } /** * Method to get the points for all the words made in the last move. * * @return map of words and their points */ public Map getWordPoints() { Map wordPoints = new HashMap<>(); for (String word : words) { wordPoints.put(word, getWordPoint(word)); } return wordPoints; } private int getWordPoint(String word) { int wordPoints = 0; Tile[][] tiles = board.getTiles(); for (int i = 0; i < GAME_SIZE; i++) { for (int j = 0; j < GAME_SIZE; j++) { Tile tile = tiles[i][j]; if (tile != null) { int x = i; int y = j; int letterScore = tile.getLetter().getValue(); if (board.isOnDoubleLetter(x, y)) { letterScore *= DOUBLE_LETTER; } if (board.isOnTripleLetter(x, y)) { letterScore *= TRIPLE_LETTER; } wordPoints += letterScore; } } } if (board.isOnDoubleWord(words.get(0))) { wordPoints *= DOUBLE_WORD; } if (board.isOnTripleWord(words.get(0))) { wordPoints *= TRIPLE_WORD; } wordPoints += word.length() * POINTS_PER_TILE; return wordPoints; } /** * Method to check if move is exchange. * * @param move move that needs to be checked * @return true if move is exchange else false */ public boolean checkExchange(Move move) { if (move.getTiles().size() == getCurrentPlayer().getHandSize()) { for (Tile tile : move.getTiles()) { getCurrentPlayer().removeTile(tile); bag.addTile(tile); } getCurrentPlayer().addTiles(bag.drawTiles(INITIAL_TILES)); return true; } return false; } /** * Method to check if move is pass. * * @param move move that needs to be checked * @return true if move is pass else false */ public boolean checkPass(Move move) { return move.getTiles().isEmpty(); } /** * Method to check if move is challenge. * * @param move move that needs to be checked * @return true if move is challenge else false */ public boolean checkChallenge(Move move) { return !words.isEmpty() && move.getTiles().isEmpty(); } /** * Method to check if challenge is successful. * * @return true if challenge is successful else false */ public boolean challengeSuccessful() { if (words.size() == 1) { return !dictionary.contains(words.get(0)); } for (String word : words) { if (!dictionary.contains(word)) { return false; } } return true; } /** * Method to set dictionary. * * @param fileName file name of dictionary * @throws FileNotFoundException if file is not found */ public void setDictionary(String fileName) throws FileNotFoundException { Scanner scanner = new Scanner(new File(fileName)); while (scanner.hasNext()) { dictionary.add(scanner.next()); } } }
Ultimo aggiornamento
30 Mar 2025
Giulia Romano
Giulia Romano

Professionista nella creazione di contenuti chiari e utili per aiutare gli utenti a richiedere preventivi e scegliere il servizio giusto.