<commit_before>﻿// This file is licensed to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Spines.Mahjong.Analysis.Classification;

namespace Spines.Hana.Clay.ViewModels
{
  internal class TileViewModel : ViewModelBase
  {
    public TileViewModel(Tile tile, int x, int y, int playerPosition)
    {
      Tile = tile;
      X = x;
      Y = y;

      var path = GetPath(tile, playerPosition);
      var image = new BitmapImage(new Uri(path, UriKind.Absolute));
      image.Freeze();
      Source = image;
    }

    private static string GetPath(Tile tile, int playerPosition)
    {
      var c = SuitCharacters[tile.Suit];
      var tileNumber = tile.Aka ? "e" : (tile.Index + 1).ToString();
      var location = tile.Location;
      if (playerPosition == 0)
      {
        switch (location)
        {
          case TileLocation.Concealed:
            return Path.Combine(PerspectivePath, $"0{c}{tileNumber}.png");
          case TileLocation.Discarded:
          case TileLocation.Melded:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}{c}{tileNumber}.png");
          case TileLocation.Added:
          case TileLocation.Called:
          case TileLocation.Riichi:
            return Path.Combine(PerspectivePath, $"{1 + (playerPosition + 1) % 4}{c}{tileNumber}.png");
          case TileLocation.FaceDown:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}j9.png");
        }
      }
      else if (playerPosition == 1)
      {
        switch (location)
        {
          case TileLocation.Concealed:
            return Path.Combine(PerspectivePath, "vertr.png");
          case TileLocation.Discarded:
          case TileLocation.Melded:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}{c}{tileNumber}.png");
          case TileLocation.Added:
          case TileLocation.Called:
          case TileLocation.Riichi:
            return Path.Combine(PerspectivePath, $"{1 + (playerPosition + 1) % 4}{c}{tileNumber}.png");
          case TileLocation.FaceDown:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}j9.png");
        }
      }
      else if (playerPosition == 2)
      {
        switch (location)
        {
          case TileLocation.Concealed:
            return Path.Combine(PerspectivePath, "0j9.png");
          case TileLocation.Discarded:
          case TileLocation.Melded:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}{c}{tileNumber}.png");
          case TileLocation.Added:
          case TileLocation.Called:
          case TileLocation.Riichi:
            return Path.Combine(PerspectivePath, $"{1 + (playerPosition + 1) % 4}{c}{tileNumber}.png");
          case TileLocation.FaceDown:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}j9.png");
        }
      }
      else if (playerPosition == 3)
      {
        switch (location)
        {
          case TileLocation.Concealed:
            return Path.Combine(PerspectivePath, "vertl.png");
          case TileLocation.Discarded:
          case TileLocation.Melded:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}{c}{tileNumber}.png");
          case TileLocation.Added:
          case TileLocation.Called:
          case TileLocation.Riichi:
            return Path.Combine(PerspectivePath, $"{1 + (playerPosition + 1) % 4}{c}{tileNumber}.png");
          case TileLocation.FaceDown:
            return Path.Combine(PerspectivePath, $"{1 + playerPosition}j9.png");
        }
      }
      return Path.Combine(FlatPath, $"{c}{tileNumber}.png");<commit_msg>Refactoring<commit_after>﻿// This file is licensed to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Spines.Mahjong.Analysis.Classification;

namespace Spines.Hana.Clay.ViewModels
{
  internal class TileViewModel : ViewModelBase
  {
    public TileViewModel(Tile tile, int x, int y, int playerPosition)
    {
      Tile = tile;
      X = x;
      Y = y;

      var path = GetPath(tile, playerPosition);
      var image = new BitmapImage(new Uri(path, UriKind.Absolute));
      image.Freeze();
      Source = image;
    }

    private static string GetPath(Tile tile, int playerPosition)
    {
      var c = SuitCharacters[tile.Suit];
      var tileNumber = tile.Aka ? "e" : (tile.Index + 1).ToString();
      switch (tile.Location)
      {
        case TileLocation.Concealed:
          switch (playerPosition)
          {
            case 0:
              return Path.Combine(PerspectivePath, $"0{c}{tileNumber}.png");
            case 1:
              return Path.Combine(PerspectivePath, "vertr.png");
            case 2:
              return Path.Combine(PerspectivePath, "0j9.png");
            case 3:
              return Path.Combine(PerspectivePath, "vertl.png");
          }
          break;
        case TileLocation.Discarded:
        case TileLocation.Melded:
          return Path.Combine(PerspectivePath, $"{1 + playerPosition}{c}{tileNumber}.png");
        case TileLocation.Added:
        case TileLocation.Called:
        case TileLocation.Riichi:
          return Path.Combine(PerspectivePath, $"{1 + (playerPosition + 1) % 4}{c}{tileNumber}.png");
        case TileLocation.FaceDown:
          return Path.Combine(PerspectivePath, $"{1 + playerPosition}j9.png");
      }
      return Path.Combine(FlatPath, $"{c}{tileNumber}.png");
{'fraction_non_alphanumeric': 0.11247157600139933, 'fraction_numerical': 0.008046178065418927, 'mean_word_length': 2.421903052064632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '370544', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1677, 'n_words': 376}