Skip to content

Instantly share code, notes, and snippets.

@Daniel-sims
Last active April 8, 2018 13:08
Show Gist options
  • Save Daniel-sims/2971db27c77a5f0f72ca4d4d8ac887f0 to your computer and use it in GitHub Desktop.
Save Daniel-sims/2971db27c77a5f0f72ca4d4d8ac887f0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace MCVE
{
class Program
{
static void Main(string[] args)
{
int[] friendlyChampionIds = {14};
int[] enemyChampionIds = {};
// This list includes the teams
// 1. 22,55,14,15,62 vs 14,11,16,51,32
// 2. 14,15,22,76,16 vs 61,78,94,11,25
// 3. 22,11,61,59,42 vs 24,14,17,67,14
//Input lists
// friendlyChampionIds = {22} & enemyChampionIds = {32}; returns match 1; as 22 and 32 are on opposite teams
// friendlyChampionIds = {22} & enemyChampionIds = {}; returns match 1 and 3; as 22 Id 22 is on either team
// friendlyChampionIds = {55,15} & enemyChampionIds = {11,16,51}; returns match 1; as the team contains the ids
// enemyChampionIds = {22,11,59} & friendlyTeamChampionIds = {}; returns match 3 as one team matches the ids given
// each list of Ids need to exist on the opposite team
var listOfMatches = GetListOfMatches();
var fullMatchupMatches = listOfMatches
.Where(q => q.Teams.Zip(new[] { friendlyChampionIds, enemyChampionIds }, (t, n) => n.All(nn => t.Players.All(x => friendlyChampionIds.Contains(x.ChampionId)))).All()
||
q.Teams.Reverse().Zip(new[] { friendlyChampionIds, enemyChampionIds }, (t, n) => n.All(nn => t.Players.Contains(n))).All());
Console.WriteLine("Hello World!");
}
public class Match
{
public IList<Team> Teams { get; set; } = new List<Team>();
}
public class Team
{
public IList<Player> Players { get; set; } = new List<Player>();
}
public class Player
{
public int ChampionId { get; set; }
}
public static IList<Match> GetListOfMatches()
{
IList<Match> matches = new List<Match>();
var matchOne = new Match();
matchOne.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 22},
new Player() {ChampionId = 55},
new Player() {ChampionId = 15},
new Player() {ChampionId = 76},
new Player() {ChampionId = 99},
}
});
matchOne.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 61},
new Player() {ChampionId = 63},
new Player() {ChampionId = 19},
new Player() {ChampionId = 85},
new Player() {ChampionId = 92},
}
});
matches.Add(matchOne);
var matchTwo = new Match();
matchTwo.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 22},
new Player() {ChampionId = 55},
new Player() {ChampionId = 15},
new Player() {ChampionId = 76},
new Player() {ChampionId = 99},
}
});
matchTwo.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 22},
new Player() {ChampionId = 55},
new Player() {ChampionId = 15},
new Player() {ChampionId = 76},
new Player() {ChampionId = 99},
}
});
matches.Add(matchTwo);
var matchThree = new Match();
matchThree.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 22},
new Player() {ChampionId = 55},
new Player() {ChampionId = 15},
new Player() {ChampionId = 76},
new Player() {ChampionId = 99},
}
});
matchThree.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 22},
new Player() {ChampionId = 55},
new Player() {ChampionId = 15},
new Player() {ChampionId = 76},
new Player() {ChampionId = 99},
}
});
matches.Add(matchThree);
var matchFour = new Match();
matchFour.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 52},
new Player() {ChampionId = 41},
new Player() {ChampionId = 15},
new Player() {ChampionId = 51},
new Player() {ChampionId = 17},
}
});
matchFour.Teams.Add(new Team()
{
Players = new List<Player>()
{
new Player() {ChampionId = 77},
new Player() {ChampionId = 36},
new Player() {ChampionId = 92},
new Player() {ChampionId = 41},
new Player() {ChampionId = 14},
}
});
matches.Add(matchFour);
return matches;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment